admin.views.decorators.staff_member_required()

staff_member_required(redirect_field_name='next', login_url='admin:login') [source] This decorator is used on the admin views that require authorization. A view decorated with this function will having the following behavior: If the user is logged in, is a staff member (User.is_staff=True), and is active (User.is_active=True), execute the view normally. Otherwise, the request will be redirected to the URL specified by the login_url parameter, with the originally requested path in a query str

gis.gdal.GDALRaster.height

height The height of the source in pixels (Y-axis). >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).height 20

forms.ModelChoiceField.to_field_name

to_field_name This optional argument is used to specify the field to use as the value of the choices in the field’s widget. Be sure it’s a unique field for the model, otherwise the selected value could match more than one object. By default it is set to None, in which case the primary key of each object will be used. For example: # No custom to_field_name field1 = forms.ModelChoiceField(queryset=...) would yield: <select id="id_field1" name="field1"> <option value="obj1.pk">Obje

views.decorators.csrf.requires_csrf_token()

requires_csrf_token(view) Normally the csrf_token template tag will not work if CsrfViewMiddleware.process_view or an equivalent like csrf_protect has not run. The view decorator requires_csrf_token can be used to ensure the template tag does work. This decorator works similarly to csrf_protect, but never rejects an incoming request. Example: from django.views.decorators.csrf import requires_csrf_token from django.shortcuts import render @requires_csrf_token def my_view(request): c = {}

test.SimpleTestCase.assertContains()

SimpleTestCase.assertContains(response, text, count=None, status_code=200, msg_prefix='', html=False) [source] Asserts that a Response instance produced the given status_code and that text appears in the content of the response. If count is provided, text must occur exactly count times in the response. Set html to True to handle text as HTML. The comparison with the response content will be based on HTML semantics instead of character-by-character equality. Whitespace is ignored in most case

db.models.expressions.When

class When(condition=None, then=None, **lookups) [source] A When() object is used to encapsulate a condition and its result for use in the conditional expression. Using a When() object is similar to using the filter() method. The condition can be specified using field lookups or Q objects. The result is provided using the then keyword. Some examples: >>> from django.db.models import When, F, Q >>> # String arguments refer to fields; the following two examples are equivalent

template.context_processors.debug()

debug() [source] If this processor is enabled, every RequestContext will contain these two variables – but only if your DEBUG setting is set to True and the request’s IP address (request.META['REMOTE_ADDR']) is in the INTERNAL_IPS setting: debug – True. You can use this in templates to test whether you’re in DEBUG mode. sql_queries – A list of {'sql': ..., 'time': ...} dictionaries, representing every SQL query that has happened so far during the request and how long it took. The list is i

Models and databases

A model is the single, definitive source of data about your data. It contains the essential fields and behaviors of the data you’re storing. Generally, each model maps to a single database table. Models Making queries Aggregation Search Managers Performing raw SQL queries Database transactions Multiple databases Tablespaces Database access optimization Examples of model relationship API usage

core.files.uploadedfile.UploadedFile.name

UploadedFile.name The name of the uploaded file (e.g. my_file.txt).

http.Http404

class django.http.Http404 When you return an error such as HttpResponseNotFound, you’re responsible for defining the HTML of the resulting error page: return HttpResponseNotFound('<h1>Page not found</h1>') For convenience, and because it’s a good idea to have a consistent 404 error page across your site, Django provides an Http404 exception. If you raise Http404 at any point in a view function, Django will catch it and return the standard error page for your application, along w