Login from shell in a Django site
-
30-10-2019 - |
Pergunta
My 1.2.3 django site uses contrib.auth
and my goal is to use the wkhtmltopdf command line to print a login-only page, wkhtml can handle this situation.
So I tested a login with curl, to be sure it's possible
The problem is that I always get a 403 CSRF (or cookie) protection errors.
I've tried to do disable CSRF with a second login view :
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 the login.txt containing username=Bob&password=secret&next=/page_to_print/id/
But the 403 CSRF error still shows up (and I don't really know if it's related to CSRF or session cookies at his point...)
Nenhuma solução correta
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow