retrieving list items from request.POST in django/python

Question:

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?

Asked By: prateek

||

Answers:

Try following django >1.4 and use

request.POST.dict()
Answered By: dev verma

If you’re in a form, a better approach is:

posted = self.fields[field_name].widget.value_from_datadict(
    self.data, self.files, self.add_prefix(field_name)
)

This will return a list if appropriate for the field, and apply cleaning, prefixing, etc. (I copied this from Django form form.cleaned_data method.)

Answered By: Chris
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.