1👍
✅
You dont have to convert a dictionary to string when using requests
library’s json
option. This should work:
import requests
data = {'login': 'mylogin', 'password': 'mypassword', 'mail': 'mymail'}
r = requests.post('http://127.0.0.1:8000/register_new_user', json=data)
0👍
The solution is to use ast.literal_eval(request.data)
to convert the string to a dictionary. I use request.data
instead of manually parsing request.body
.
However, v1k45’s answer is the best solution, as I do not need to convert my dict to a string before sending my request.
- I couldn't store the values in database from the custom form in HTML page. Using Django
- Django – TypeError: int() argument must be a string or a number, not 'dict'
- Django: MultiChoiceField does not show saved choices added after creation
Source:stackexchange.com