0👍
✅
It appeared that Set-Cookie
is a wrong header for consequent requests. Cookie
should be used instead:
>>> get = Request('http://127.0.0.1:8000/api/do-stuff')
>>> get.add_header('Cookie', 'csrftoken=53eX5pwRzV4fR...') # just csrftoken here
>>> get_resp = urlopen(get)
1👍
Try to use Django’s test client instead of urllib.
>>> from django.test import Client
>>> c = Client()
>>> response = c.post('/login/', {'username': 'john', 'password': 'smith'})
>>> response.status_code
200
>>> response = c.get('/customer/details/')
>>> response.content
b'<!DOCTYPE html...'
See: documentation
- What is the best way of saving related model in django admin?
- (Django) save(*args, **kwargs) vs. save(**kwargs)
- Adding Django-admin-action with conditions
- When doing a POST request on a model from a form it doesn't assign an ID to the object
Source:stackexchange.com