1👍
✅
You should use a method_decorator
on the dispatch
method:
from django.utils.decorators import method_decorator
class ContactFormView(FormView):
...
@method_decorator(csrf_protect)
def dispatch(self, *args, **kwargs):
return super(ContactFormView, self).dispatch(*args, **kwargs)
However, it’s highly recommended to use the CsrfViewMiddleware
instead. Otherwise, a single instance where you happen to forget the decorator will immediately impose a security risk.
👤knbk
Source:stackexchange.com