HTML Form Building / Django request.POST help HTML Form Building / Django request.POST help django django

HTML Form Building / Django request.POST help


If you're expecting a list for the key attach, you should use request.POST.getlist('attach'). Doing request.POST['attach'] will only give you the last value, which is a string.

Happy new year!


Once again I'll point to my old friend the jQuery taconite plugin. If you are using AJAX to push the image to the server, try returning a taconite response which makes multiple changes (sticks the ID in one place, appends a hidden input someplace else, etc.) to your DOM. It can also run JS to do some other things within the page's environment. Very, very handy.

As far as your using the same name for multiple input fields, I'm not sure it works the way you would like. Using the Live HTTP Headers plugin for Firefox I can see foo=1&foo=2&foo=3&foo=4&foo=5&foo=6 being passed but both PHP and Django only deliver the last value, not an array. You might try creating names like "attach_1", "attach_2", etc. and just loop through your POST values and suck them out that way. Either that or get the raw POST data and parse it yourself.

See elo80ka's answer for how to do this. (Ya learn sometin' new every day!)