Hello!

Recently I started to learn Django and ran into a problem with authorization. At first, when submitting the form, the error “CSRF token missing or incorrect” was displayed. Searches on the Internet suggested that you need to register

django.middleware.csrf.CsrfResponseMiddleware 

. After adding this line to settyngs.py, the data was taken from the form, but on the site itself began to issue “A server error occurred. Please contact the administrator. ”, And the native server says “ImproperlyConfigured: Module ”django.middleware.csrf“ does not define a ”CsrfMiddleware“ attribute/class”.

If you comment everything connected with “django.middleware.csrf”, then everything starts to display normally.

Please tell me what I am wondering and how it is solved.

ps version 1.6

1 answer 1

Lay out settings.py

In any case, the standard list of middleware is enough.

Add the MIDDLE ' django.middleware.csrf.CsrfViewMiddleware ' to the django.middleware.csrf.CsrfViewMiddleware if there is none. Nothing more is required.

Well, in general, do you send in the form {% csrf_token %} ?

  • one
    Thank. It worked. Removed everything related to csrf except what you said well and added a token to the form and it all worked. Thanks again! - balalay