-1

When I add CSRF middleware django.middleware.csrf.CsrfViewMiddleware to prevent xss csrf attack I am getting error response 403 csrf error.

  • I referred to the official doc and old Stack Overflow answers but still I didn't get any idea why it causing error.
  • I read from Django official doc if I added csrf middleware it will take care all csrf validation in every views by default.
  • Along with this I have used some decorators too to ensure security like @login_required and @csrf_protect
  • I have added django.middleware.csrf.CsrfViewMiddleware as a first entry before common middleware in Middleware class, is it because of that?
halfer
  • 19,824
  • 17
  • 99
  • 186
skysoft999
  • 540
  • 1
  • 6
  • 27

1 Answers1

1

a form with CSRF in Django should look something like this:

<form method="POST" ...>
    {% csrf_token %}
...
</form>

More info here

Thomas Jiang
  • 1,303
  • 11
  • 16