On 3/29/07, olive <[EMAIL PROTECTED]> wrote:
> This is the request.POST I get from a (new)form:
> <MultiValueDict: {'application': [''], 'applicant': [''], 'step9':
> ['Register'], 'countries': ['DE', 'ES']}>
>
> No I want to have the 'countries' list but request.POST[''countries']
> gives me 'ES' instead of the entire list.

Because HTTP allows multiple values to be posted with the same "key",
Django uses a specialized dictionary-like data structure to handle the
posted values; accessing request.POST["countries"] will only return
one value, but request.POST.getlist("countries") will return them all.

This distinction can be tricky at first, but yields a nice, consistent
API -- in most cases, you only have one value posted for a given key,
so being able to treat it that way is extremely handy (compare to the
other possibility, in which the values would always have to be lists
and you'd have to manually index them to get at the common case).

See here for full documentation of how these data structures work:

http://www.djangoproject.com/documentation/request_response/#querydict-objects

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to