How-to
How to implement a custom template backend
Here’s how to implement a custom template backend in order to use another template system. A template backend is a class that inherits django.template.backends.base.BaseEngine. It must implement get_template() and optionally from_string().
4.2
5.0
5.1
5.2
6.0
Reference
Generic editing views
classdjango.views.generic.edit.FormView : A view that displays a form. On error, redisplays the form with validation errors; on success, redirects to a new URL. classdjango.views.generic.edit.BaseFormView : A base view for displaying a form.
4.2
5.0
5.1
5.2
6.0
Topic guide
Templates
The Django template languageSyntax
Tags provide arbitrary logic in the rendering process. This definition is deliberately vague. For example, a tag can output content, serve as a control structure e.g.
4.2
5.0
5.1
5.2
6.0
Topic guide
Templates
Support for template engines
Template objects returned by get_template() and select_template() must provide a render() method with the following signature: Template.render(context=None,request=None) : Renders this template with a given context. Here’s an example of the search algorithm.
4.2
5.0
5.1
5.2
6.0
Reference
Middleware
After UpdateCacheMiddleware: Modifies Vary header. 4. SessionMiddleware Before any middleware that may raise an exception to trigger an error view (such as PermissionDenied) if you’re using CSRF_USE_SESSIONS. After UpdateCacheMiddleware: Modifies Vary header. 5.
dev
Reference
Middleware
After UpdateCacheMiddleware: Modifies Vary header. 4. SessionMiddleware Before any middleware that may raise an exception to trigger an error view (such as PermissionDenied) if you’re using CSRF_USE_SESSIONS. After UpdateCacheMiddleware: Modifies Vary header. 5.
4.2
5.0
5.1
5.2
6.0
Index
… - wordwrap - yesno - template tag - autoescape - block - blocktrans - blocktranslate - cache - comment - csrf_token - cycle - debug - extends - filter - firstof - for - get_available_languages - get_current_language - get_current_language_bidi - …
Reference
Generic editing views
classdjango.views.generic.edit.CreateView : A view that displays a form for creating an object, redisplaying the form with validation errors (if there are any) and saving the object. classdjango.views.generic.edit.BaseCreateView : A base view for creating a new object instance.
dev
Reference
Generic editing views
classdjango.views.generic.edit.UpdateView : A view that displays a form for editing an existing object, redisplaying the form with validation errors (if there are any) and saving changes to the object.
dev
Reference
Generic editing views
classdjango.views.generic.edit.DeleteView : A view that displays a confirmation page and deletes an existing object. The given object will only be deleted if the request method is POST.
dev
Topic guide
Using the Django authentication system
classLogoutView[source] : Logs a user out on POST requests.
dev
Topic guide
Time zones
The current time zone is the equivalent of the current locale for translations. However, there’s no equivalent of the Accept-Language HTTP header that Django could use to determine the user’s time zone automatically. Instead, Django provides time zone selection functions.
dev
Topic guide
Translation
set_language(request)[source] As a convenience, Django comes with a view, django.views.i18n.set_language(), that sets a user’s language preference and redirects to a given URL or, by default, back to the previous page.
dev
Topic guide
Templates
when using render()), the Jinja2 backend adds the globals request, csrf_input, and csrf_token to the context. Apart from that, this backend doesn’t create a Django-flavored environment. It doesn’t know about Django filters and tags.
dev
Reference
Generic editing views
classdjango.views.generic.edit.CreateView : A view that displays a form for creating an object, redisplaying the form with validation errors (if there are any) and saving the object. classdjango.views.generic.edit.BaseCreateView : A base view for creating a new object instance.
4.2
5.0
5.1
5.2
6.0
Reference
Generic editing views
classdjango.views.generic.edit.UpdateView : A view that displays a form for editing an existing object, redisplaying the form with validation errors (if there are any) and saving changes to the object.
4.2
5.0
5.1
5.2
6.0
Reference
Generic editing views
classdjango.views.generic.edit.DeleteView : A view that displays a confirmation page and deletes an existing object. The given object will only be deleted if the request method is POST.
4.2
5.0
5.1
5.2
6.0
Topic guide
Using the Django authentication system
Authentication in web requestsAuthentication Views
classLogoutView[source] : Logs a user out on POST requests.
4.2
5.0
5.1
5.2
6.0
Topic guide
Time zones
Concepts
The current time zone is the equivalent of the current locale for translations. However, there’s no equivalent of the Accept-Language HTTP header that Django could use to determine the user’s time zone automatically. Instead, Django provides time zone selection functions.
4.2
5.0
5.1
5.2
6.0
Topic guide
Translation
Miscellaneous
set_language(request)[source] As a convenience, Django comes with a view, django.views.i18n.set_language(), that sets a user’s language preference and redirects to a given URL or, by default, back to the previous page.
4.2
5.0
5.1
5.2
6.0