See the django document snippet.
Decorator Method Instead of adding CsrfViewMiddleware as a protective wrapper, you can use the csrf_protect decorator, which has exactly the same functionality for certain views that need protection. It should be used for both representations that insert the CSRF token into the output file, and those that accept POST form data. (This is often the same viewing function, but not always). It is used as follows:
from django.views.decorators.csrf import csrf_protect from django.template import RequestContext @csrf_protect def my_view(request): c = {}
Using the decorator alone is not recommended , because if you forget to use it, you will have a security hole. A strategy for using belts and braces to use both is good and will have minimal overhead.
Tairan
source share