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:
1 2 3 4 5 6 7 8 | from django.views.decorators.csrf import requires_csrf_token from django.shortcuts import render @requires_csrf_token def my_view(request): c = {} # ... return render(request, "a_template.html" , c) |
Please login to continue.