I’m developing a just-for-learn iOS app who interacts with my Django application.
I’m at login part: my client fails to login into Django app due to csrf protection.
For the others views I just would add csrf_exempt decorator for disable it, but for built-in django.contrib.auth.views.login ?
In modern Django (last tested on 1.11), one way to disable the CSRF check is to subclass the
LoginViewand override itsdispatchmethod, which is explicitly decorated withcsrf_protect(as seen here).The resulting CBV is along the lines of:
See the entire
urls.pyfile here.The idea is to replicate the exact same method, while replacing
csrf_protectwithcsrf_exempt. There might be a cleaner way to do this, for example, using undecorated.