4👍
There are two requirements for this to work:
- csrftoken should be passed inside the form data as csrfmiddlewaretoken.
- Along with X-CSRFToken header, Referer header
is also required.
The code would then look like:
self.client.post(
'/check_login/',
{
'username': '####',
'password': '########',
'csrfmiddlewaretoken': csrftoken
},
headers={
'X-CSRFToken': csrftoken,
'Referer': self.parent.host + '/check_login/'
})
2👍
def on_start(self):
self.login()
def login(self):
# login to the application
self.client.auth = HTTPBasicAuth('username', 'password')
this is enough for login. no need to update csrftoken in python. 3.6.8
0👍
I had the same problem.
I have Django 1.11 instance and the name of csrftoken is other, in my case is:
csrftoken = response.cookies['csrftoken_myproject']
And I have searched the csrftoken name with the devtools of Chromium browser (for example).
- [Django]-Passing context from child to parent template in Django
- [Django]-Django Cors Allow Access-Control-Allow-Headers
- [Django]-Django forms error 'got multiple values for keyword argument 'choices''
Source:stackexchange.com