On Oct 19, 4:36 pm, "mike.thon" <mike.t...@gmail.com> wrote:
> Hi all - I am quite new to python and Django but I'm starting to learn
> my way around. I am writing a form for uploading files but the form
> always seems to fail the form.is_valid() test. if I print the form
> errors using:
>
> errors = form.errors
> print errors
>
> I get this string:
>
> <ul class="errorlist"><li>file<ul class="errorlist"><li>This field is
> required.</li></ul></li></ul>
>
> I can read the file name and file contents from the request.FILES
> object and the data is there but is_valid() seems to always return
> False. I guess there must be a default clean() method on uploaded
> files that always returns false unless I override it? I think I can
> write my own validator method and put it in clean_<fieldname>() in the
> form subclass but I would like to find out why the error is happening
> before I do that.
>
> BTW, I can upload the same file through the admin interface and I do
> not get the error.
> TIA
Well, I found the problem - When binding the POST data to the form,
you also need to specify the form file data (request.FILES)
http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form
Thanks anyway!
--~--~---------~--~----~------------~-------~--~----~
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
django-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---