On Jan 3, 2008 10:49 AM, Chris Haynes <[EMAIL PROTECTED]> wrote:

>
> With the following form in my template
>
> <form enctype="multipart/form-data" method="post" action="/submit/">
> <p><label for="file">File: </label>
> {{ form.code }}
> <input type="SUBMIT" value="Submit">
> </p>
> </form>
>
> and the appended view code, I get the desired form with text box,
> Browse... and Submit buttons. But when
> browse for a plain text file and hit Submit, I get the
> HttpResponseBadRequest response and the print statements flagged with
> ##  below print the following to the server console.
> <MultiValueDict: {'code': [{'content': '<omitted>', 'content-type':
> 'application
> /octet-stream', 'filename': 'README.txt'}]}>
> {'code': None}
>
> Why is clean_data == {'code': None} ?
>
> -------------------------------
> class SubmissionForm(forms.Form):
>    code = forms.Field(widget=forms.FileInput, required=False,
>                       label=_('File'), help_text=_('Upload a file'))
>

Why not forms.FileField here?


>
> def submit(request):
>    if request.method == 'POST':
>        new_data = request.POST.copy()
>        new_data.update(request.FILES)
>        print request.FILES##
>        form = SubmissionForm(new_data)


Instead of this copy/update I think you should be doing:

form = SubmissionForm(request.POST, request.FILES)

as per the doc here:

http://www.djangoproject.com/documentation/newforms/#binding-uploaded-files-to-a-form

I note this is marked as "new in development version", as is FileField, so
perhaps you are running 0.96 and trying to get file upload working?
Personally I'd recommend using an SVN checkout instead, especially if you
are running into wanting to do things that have been added since 0.96.

Karen

--~--~---------~--~----~------------~-------~--~----~
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