prepopulate file fields in forms after validation errors

283 views
Skip to first unread message

Bastien

unread,
May 26, 2009, 7:30:53 AM5/26/09
to Django users
Hi,

When I have some validation errors in my forms they automatically get
reloaded after POST with all the fields already filled with what the
user already introduced before POST and she only has to change
whatever was wrong in the first place. But for files or images, the
path disappears and the user has to choose again which image she wants
to upload. I'd like these fields to appear populated along the others.

I thought sending form = Form(request.POST, request.FILES) to the
template was enough. Is there something I missed or do these fields
need to be populated in another way?

thanks,
Bastien

Daniel Roseman

unread,
May 26, 2009, 7:42:53 AM5/26/09
to Django users
This question comes up here occasionally. Here's what I said last
time:

This isn't a Django issue. It's a standard property of browsers: you
can't set an initial value for file input fields. This is a security
measure, to stop malicious pages uploading files from your hard drive
without your explicit instruction.
There isn't really any way round it, except to do something extremely
complicated like GMail does and upload the file in the background
while the user fills in the form, then replace the file field with a
reference to the uploaded version of the file.
--
DR.

Bastien

unread,
May 26, 2009, 7:51:16 AM5/26/09
to Django users
Thank you Daniel, then the users will just re enter the files and feel
secure :)

On May 26, 1:42 pm, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages