Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieving list items from request.POST in django/python

Tags:

python

django

In my request.POST i am getting a query dictionary , one of the items in this dictionary is a list with multiple items (pass_id) eg.

I want to retrieve each of the values in pass_id and store in a new list. Can you suggest the code for this?

like image 626
prateek Avatar asked Mar 25 '11 09:03

prateek


People also ask

How do you receive data from a Django form with a post request?

Using Form in a View In Django, the request object passed as parameter to your view has an attribute called "method" where the type of the request is set, and all data passed via POST can be accessed via the request. POST dictionary. The view will display the result of the login form posted through the loggedin.

How can I get post request in Django?

Django pass POST data to view The input fields defined inside the form pass the data to the redirected URL. You can define this URL in the urls.py file. In this URLs file, you can define the function created inside the view and access the POST data as explained in the above method. You just have to use the HTTPRequest.

What does request POST do in Django?

Django puts data in request. POST when a user submits a form with the attribute method="post" . Line 10: You retrieve the submitted value by accessing the data at the key "follow" , which you defined in your template with the name HTML attribute on your <button> elements.


2 Answers

http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict.getlist

request.POST.getlist('pass_id') 
like image 50
DrMeers Avatar answered Oct 09 '22 15:10

DrMeers


Try following django >1.4 and use

request.POST.dict() 
like image 36
dev verma Avatar answered Oct 09 '22 17:10

dev verma