djangodocs.org

155 sections in Django 5.2 Search all versions →

CSRF_USE_SESSIONS

Reference Settings Core Settings

Default: False Whether to store the CSRF token in the user’s session instead of in a cookie. It requires the use of django.contrib.sessions.

CSRF_COOKIE_HTTPONLY

Reference Settings Core Settings

Default: False Whether to use HttpOnly flag on the CSRF cookie. If this is set to True, client-side JavaScript will not be able to access the CSRF cookie.

How-to

To take advantage of CSRF protection in your views, follow these steps: The CSRF middleware is activated by default in the MIDDLEWARE setting.

How it works

Reference Cross Site Request Forgery protection

The CSRF protection is based on the following things: A CSRF cookie that is a random secret value, which other sites will not have access to. CsrfViewMiddleware sends this cookie with the response whenever django.middleware.csrf.get_token() is called.