djangodocs.org

309 sections across all versions Narrow to Django 6.0 (current) →

The template

Topic guide Working with forms

NOTE: Django ships with an easy-to-use protection against Cross Site > Request Forgeries. When submitting a form via POST with > CSRF protection enabled you must use the csrf_token template tag as > in the preceding example.

dev

The template

Topic guide Working with forms Building a formBuilding a form in Django

NOTE: Django ships with an easy-to-use protection against Cross Site > Request Forgeries. When submitting a form via POST with > CSRF protection enabled you must use the csrf_token template tag as > in the preceding example.

4.2 5.0 5.1 5.2 6.0

1.4

Internals Django Deprecation Timeline

See the Django 1.2 release notes for more details on these changes. CsrfResponseMiddleware and CsrfMiddleware will be removed. Use the {% csrf_token %} template tag inside forms to enable CSRF protection. CsrfViewMiddleware remains and is enabled by default.

dev

Usage

Topic guide Templates

Here’s an example of the search algorithm.

dev

1.4

Internals Django Deprecation Timeline

See the Django 1.2 release notes for more details on these changes. CsrfResponseMiddleware and CsrfMiddleware will be removed. Use the {% csrf_token %} template tag inside forms to enable CSRF protection. CsrfViewMiddleware remains and is enabled by default.

6.0

1.4

Internals Django Deprecation Timeline

See the Django 1.2 release notes for more details on these changes. CsrfResponseMiddleware and CsrfMiddleware will be removed. Use the {% csrf_token %} template tag inside forms to enable CSRF protection. CsrfViewMiddleware remains and is enabled by default.

5.2

1.6

Internals Django Deprecation Timeline

The csrf_response_exempt and csrf_view_exempt decorators will be removed. Since 1.4 csrf_response_exempt has been a no-op (it returns the same function), and csrf_view_exempt has been a synonym for django.views.decorators.csrf.csrf_exempt, which should be used to replace it.

5.0 5.1 6.0

1.7

Internals Django Deprecation Timeline

The undocumented check_for_test_cookie method in AuthenticationForm will be removed following an accelerated deprecation. Users subclassing this form should remove calls to this method, and instead ensure that their auth related views are CSRF protected, which ensures that cookies are enabled.

4.2 5.2 6.0

Utilities

Reference Cross Site Request Forgery protection

csrf_exempt(view)[source] : This decorator marks a view as being exempt from the protection ensured by the middleware. Example: csrf_protect(view) : Decorator that provides the protection of CsrfViewMiddleware to a view.

dev

Utilities

Reference Cross Site Request Forgery protection

csrf_exempt(view)[source] : This decorator marks a view as being exempt from the protection ensured by the middleware. Example: csrf_protect(view) : Decorator that provides the protection of CsrfViewMiddleware to a view.

4.2 5.0 5.1 5.2 6.0

Decorators

Topic guide Asynchronous support Async views

The following decorators can be used with both synchronous and asynchronous view functions: cache_control() never_cache() no_append_slash() csp_override() csp_report_only_override() csrf_exempt() csrf_protect() ensure_csrf_cookie() requires_csrf_token() sensitive_variables() sensitive_post_parameters() gzip_page() condition() conditional_page() etag() last_modified() require_http_methods() require_GET() require_POST() require_safe() vary_on_cookie() vary_on_headers() xframe_options_deny() xframe_options_sameorigin() xframe_options_exempt() For example:

5.0 5.1 5.2 6.0

Custom backends

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().

dev

FormView

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.

dev

Decorators

Topic guide Asynchronous support

The following decorators can be used with both synchronous and asynchronous view functions: cache_control() never_cache() no_append_slash() csp_override() csp_report_only_override() csrf_exempt() csrf_protect() ensure_csrf_cookie() requires_csrf_token() sensitive_variables() sensitive_post_parameters() gzip_page() condition() conditional_page() etag() last_modified() require_http_methods() require_GET() require_POST() require_safe() vary_on_cookie() vary_on_headers() xframe_options_deny() xframe_options_sameorigin() xframe_options_exempt() For example: …

dev

Tags

Topic guide Templates

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.

dev