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'))
def submit(request):
if request.method == 'POST':
new_data = request.POST.copy()
new_data.update(request.FILES)
print request.FILES##
form = SubmissionForm(new_data)
if form.is_valid():
clean_data = form.cleaned_data
print clean_data##
if clean_data['code']:
submission = Submission()
submission.name = code.filename
submission.save_code_file(code.filename, code.content)
context = Context({'length': str(len(code.content)),
'name': code.filename})
return render_to_response('submit/submitted.html',
context)
else:
return HttpResponseBadRequest('Bad file')
else:
return HttpResponseServerError('Bad form')
else:
context = Context({'form': SubmissionForm()})
return render_to_response('submit/index.html', context)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---