test.utils.teardown_test_environment()

teardown_test_environment() [source] Performs global post-test teardown, such as removing instrumentation from the template system and restoring normal email services.

db.transaction.clean_savepoints()

clean_savepoints(using=None) [source] Resets the counter used to generate unique savepoint IDs. The following example demonstrates the use of savepoints: from django.db import transaction # open a transaction @transaction.atomic def viewfunc(request): a.save() # transaction now contains a.save() sid = transaction.savepoint() b.save() # transaction now contains a.save() and b.save() if want_to_keep_b: transaction.savepoint_commit(sid) # open transa

utils.cache.add_never_cache_headers()

add_never_cache_headers(response) [source] Adds a Cache-Control: max-age=0, no-cache, no-store, must-revalidate header to a response to indicate that a page should never be cached. Changed in Django 1.8.8: In older versions, Cache-Control: max-age=0 was sent. This didn’t reliably prevent caching in all browsers.

gis.geoip.GeoIP.country_code_by_name()

GeoIP.country_code_by_name(query)

db.models.query.QuerySet.select_related()

select_related(*fields) Returns a QuerySet that will “follow” foreign-key relationships, selecting additional related-object data when it executes its query. This is a performance booster which results in a single more complex query but means later use of foreign-key relationships won’t require database queries. The following examples illustrate the difference between plain lookups and select_related() lookups. Here’s standard lookup: # Hits the database. e = Entry.objects.get(id=5) # Hits

views.decorators.csrf.csrf_protect()

csrf_protect(view) Decorator that provides the protection of CsrfViewMiddleware to a view. Usage: from django.views.decorators.csrf import csrf_protect from django.shortcuts import render @csrf_protect def my_view(request): c = {} # ... return render(request, "a_template.html", c) If you are using class-based views, you can refer to Decorating class-based views.

gis.gdal.LineString.y

y Returns a list of Y coordinates in this line: >>> OGRGeometry('LINESTRING (1 2,3 4)').y [2.0, 4.0]

How to deploy with WSGI

Django’s primary deployment platform is WSGI, the Python standard for web servers and applications. Django’s startproject management command sets up a simple default WSGI configuration for you, which you can tweak as needed for your project, and direct any WSGI-compliant application server to use. Django includes getting-started documentation for the following WSGI servers: How to use Django with Apache and mod_wsgi Authenticating against Django’s user database from Apache How to use Django wi

admin.ModelAdmin.list_max_show_all

ModelAdmin.list_max_show_all Set list_max_show_all to control how many items can appear on a “Show all” admin change list page. The admin will display a “Show all” link on the change list only if the total result count is less than or equal to this setting. By default, this is set to 200.

gis.geos.GEOSGeometry.within()

GEOSGeometry.within(other) Returns True if the DE-9IM intersection matrix for the two geometries is T*F**F***.