Django shell login

In my 1.2.3 django site is used contrib.auth, and my goal is to use the wkhtmltopdf command line to print the page for login only, wkhtml can handle this situation .

So, I tested the login with curl to make sure it is possible.
The problem is that I always get 403 CSRF (or cookie) errors.
I tried disabling CSRF with a second login:

from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.views import login

@csrf_exempt
def fakelogin(request, template_name='registration/login.html'):
    return login(request, template_name)

This new view works as expected. Then, as mentioned here :

curl -c cookies.txt http://dev.local:8000/fakelogin/
curl -c cookies.txt -d login.txt http://dev.local:8000/fakelogin/

with login.txt file containing username=Bob&password=secret&next=/page_to_print/id/

But CSRF error 403 still appears (and I really don't know if this is due to CSRF or session files at its point ...)

+3
1

CSRF, CSRFMiddleWare settings.py. .

- twill, , , , , .

+3

Source: https://habr.com/ru/post/1790450/


All Articles