Upload file / form validation

13 views
Skip to first unread message

Bear

unread,
Aug 19, 2008, 6:50:09 AM8/19/08
to Django users
Hi.

I'm in trouble here, when I try to upload a file and pass it to my
form for validation, it tells me that the form is not valid and that
there is no file.

But my request.FILES tab seems to be just fine..

Here's my code :

class AddMediaForm(forms.Form):
file = forms.FileField()
entry = forms.CharField(required=True, max_length=50,
widget=forms.HiddenInput())

def add_file(request):
if request.method == 'POST':
print request.FILES['file'].temporary_file_path()
form = AddMediaForm(request.POST, request.FILES)
print form.errors
if form.is_valid():
if
check_uploaded_file(request.FILES['file'].content_type):
handle_uploaded_file(request.FILES['file'],
request.POST['entry'])
return HttpResponseRedirect('/
entry/'+request.POST['entry']+'/manage')
else:
return HttpResponseRedirect('/error_typefile')
else:
return HttpResponseRedirect('/error_validation')
else:
return HttpResponseRedirect('/error_nofile')

<form enctype="multipart/form-data" method="post" action="/add_file/">
{{ form_upload }}
<input type="submit" value="Upload" />
</form>

print request.FILES['file'].temporary_file_path() gives me the right
path (/tmp/..)


I'm with the last svn release.
Please someone help me. It works on another machine but I can't figure
out what is wrong here..

Thx

Reply all
Reply to author
Forward
0 new messages