X
X
xenofobius2017-07-28 21:07:19
Django
xenofobius, 2017-07-28 21:07:19

How to disable CSRF validation in django?

There is a class base view, I try to send a post request from another server, I get 403
Before the class, I connected a decorator to disable the check:

@method_decorator(csrf_exempt, name='dispatch')
class Example(TemplateView):
    template_name = 'example.html'

    def post(self, request, *args, **kwargs):
        context = self.get_context_data()
        print(request.POST)
        return super(TemplateView, self).render_to_response(context)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ksenofobius, 2017-07-28
@ksenofobius

Thank you all for your participation, I did it through the dispatch redefinition

@method_decorator(csrf_exempt)
    def dispatch(self, request, *args, **kwargs):
        return super(Example, self).dispatch(request, *args, **kwargs)

Although it is written that with 1.9+ the above-mentioned decorators solve this problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question