Friday, April 8, 2011

How to check if request.FILES is empty

Hi,
I have this form which has a couple of form items and a file upload.
Now as long as I select an image to be uploaded the form works fine
and the data is saved, however, when you try to submit the form
without uploading an image I land up getting the error
Exception Type: MultiValueDictKeyError
Exception Value:
"Key 'uploadphoto' not found in <MultiValueDict: {}>"

My code looks something like this

if request.FILES['uploadphoto']:
up = request.FILES['uploadphoto']
upn = up.name
handle_uploaded_file(up)
photo = upn

and in trace back the error is on this line "up =
request.FILES['uploadphoto'] "

How do I write an if statement where I can check if the request.FILES
is not empty then execute the below statements

Thanks for your help in advance
J

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment