djangodocs.org

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

CSRF_COOKIE_PATH

Reference Settings

Default: '/' The path set on the CSRF cookie. This should either match the URL path of your Django installation or be a parent of that path.

dev

CSRF_COOKIE_SAMESITE

Reference Settings

Default: 'Lax' The value of the SameSite flag on the CSRF cookie. This flag prevents the cookie from being sent in cross-site requests. See SESSION_COOKIE_SAMESITE for details about SameSite.

dev

CSRF_COOKIE_SECURE

Reference Settings

Default: False Whether to use a secure cookie for the CSRF cookie. If this is set to True, the cookie will be marked as “secure”, which means browsers may ensure that the cookie is only sent with an HTTPS connection.

dev

CSRF_FAILURE_VIEW

Reference Settings

Default: 'django.views.csrf.csrf_failure' A dotted path to the view function to be used when an incoming request is rejected by the CSRF protection.

dev

CSRF_TRUSTED_ORIGINS

Reference Settings

Default: [] (Empty list) A list of trusted origins for unsafe requests (e.g. POST). For requests that include the Origin header, Django’s CSRF protection requires that header match the origin present in the Host header.

dev

Reference Middleware Available middleware

classCsrfViewMiddleware[source] Adds protection against Cross Site Request Forgeries by adding hidden form fields to POST forms and checking requests for the correct value. See the Cross Site Request Forgery protection documentation.

4.2 5.0 5.1 5.2 6.0

CSRF_COOKIE_DOMAIN

Reference Settings Core Settings

Default: None The domain to be used when setting the CSRF cookie. This can be useful for easily allowing cross-subdomain requests to be excluded from the normal cross site request forgery protection.

4.2 5.0 5.1 5.2 6.0

CSRF_COOKIE_PATH

Reference Settings Core Settings

Default: '/' The path set on the CSRF cookie. This should either match the URL path of your Django installation or be a parent of that path.

4.2 5.0 5.1 5.2 6.0

CSRF_COOKIE_SAMESITE

Reference Settings Core Settings

Default: 'Lax' The value of the SameSite flag on the CSRF cookie. This flag prevents the cookie from being sent in cross-site requests. See SESSION_COOKIE_SAMESITE for details about SameSite.

4.2 5.0 5.1 5.2 6.0

CSRF_COOKIE_SECURE

Reference Settings Core Settings

Default: False Whether to use a secure cookie for the CSRF cookie. If this is set to True, the cookie will be marked as “secure”, which means browsers may ensure that the cookie is only sent with an HTTPS connection.

4.2 5.0 5.1 5.2 6.0

CSRF_FAILURE_VIEW

Reference Settings Core Settings

Default: 'django.views.csrf.csrf_failure' A dotted path to the view function to be used when an incoming request is rejected by the CSRF protection.

4.2 5.0 5.1 5.2 6.0

CSRF_TRUSTED_ORIGINS

Reference Settings Core Settings

Default: [] (Empty list) A list of trusted origins for unsafe requests (e.g. POST). For requests that include the Origin header, Django’s CSRF protection requires that header match the origin present in the Host header.

4.2 5.0 5.1 5.2 6.0

CSRF_COOKIE_MASKED

Reference Settings Core Settings

New in Django 4.1. Default: False Whether to mask the CSRF cookie. See release notes for usage details. WARNING: Deprecated since version 4.1: This transitional setting is deprecated and will be removed in Django 5.0.

4.2

Topic guide Security in Django

CSRF attacks allow a malicious user to execute actions using the credentials of another user without that user’s knowledge or consent. Django has built-in protection against most types of CSRF attacks, providing you have enabled and used it where appropriate.

dev