How to send a POST request using django?


I dont want to use html file, but only with django I have to make POST request.

Just like urllib2 sends a get request.

10/8/2015 11:41:14 AM

Accepted Answer

A combination of methods from urllib2 and urllib will do the trick. Here is how I post data using the two:

post_data = [('name','Gladys'),]     # a sequence of two element tuples
result = urllib2.urlopen('', urllib.urlencode(post_data))
content =

urlopen() is a method you use for opening urls. urlencode() converts the arguments to percent-encoded string.

3/15/2011 8:00:25 AM

Here's how you'd write the accepted answer's example using python-requests:

post_data = {'name': 'Gladys'}
response ='', data=post_data)
content = response.content

Much more intuitive. See the Quickstart for more simple examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow