Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to pass request.body via post request in django test client?

I have not found any way so far.

https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.Client.options 

shows that options allows request.body via get request but cannot find any way to pass via post request. Any ideas, I have been looking for a few hours now.

like image 927
james Avatar asked Aug 27 '15 20:08

james


2 Answers

Yes:

self.client.generic('POST', '/url', 'raw post data')
like image 94
Chris Lamb Avatar answered Oct 27 '22 08:10

Chris Lamb


If you really want to do:

request.body = b'{"first": "fred", "last": "dredd"}'

You should do it like this:

request._body = b'{"first": "fred", "last": "dredd"}'
like image 21
milorad.kukic Avatar answered Oct 27 '22 06:10

milorad.kukic