PHP is stupid. The problem with the [] syntax is that you have to be careful that the user hasn't added or removed it from your fields. This can cause problems if you were expecting an array and got a string, or vice-versa.
Instead, name the fields without [], and in your Django code, use request.POST.getlist('array'). That way you are assured to get a list no matter what values the user sent.
On Aug 26, 2016, at 2:13 PM, ggilley@gmail.com wrote:I'm trying to create an iOS app that can post multipart forms to Django. (JSON is trivial, wish it worked with file uploads. :-)What is the proper format for the HTTP request when passing arrays of values? (Strings is all I care about at the moment)I think PHP has the follow style. What is the Django equivalent? I tried reading through the sources, but it wasn't obvious.Thanks,Greg--Boundary-56A500AE-D543-43BD-93F0-6A1721A73F70
Content-Disposition: form-data; name="array[]"
one
--Boundary-56A500AE-D543-43BD-93F0-6A1721A73F70
Content-Disposition: form-data; name="array[]"
two
--Boundary-56A500AE-D543-43BD-93F0-6A1721A73F70
Content-Disposition: form-data; name="array[]"
three
--Boundary-56A500AE-D543-43BD-93F0-6A1721A73F70
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4d999852-b1eb-4b39-bbb3-46606a77d0c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Peter of the Norse
No comments:
Post a Comment