You are missing the enctype form attribute needed for files input fields. Your
form definition should be:

    <form enctype="multipart/form-data" action="" method="post">

Check http://www.w3.org/TR/html401/interact/forms.html#adef-enctype for details.

Matías


Excerpts from arapaho's message of Thu Mar 17 15:53:45 -0300 2011:
> Hi,
> 
> Rather new to Django and using 1.2.5 and Windows, I am hung up trying
> to upload a file. I get a post request with request.FILES empty.
> 
> My VIEW is:
> 
> def intro(request):
>     c = {}
>     c.update(csrf(request))
> 
>     if request.method == 'POST': #see if form submitted
> 
>         form = FileUploadForm(request.POST,request.FILES)
>         print request.FILES
>         if form.is_valid():
>             text = 'You successfully uploaded file:'
>             handle_uploaded_file(request.FILES['file'])
>     else:
>         text = 'You may upload your student data file here'
>         form = FileUploadForm()
> 
>     c['form'] = form
>     c['text'] = text
>     return render_to_response('intro.html', c)
> 
> 
> In SETTINGS I have:
> 
> ROOT_PATH = os.path.dirname(__file__)
> 
> MEDIA_ROOT = '/media/'
> 
> MEDIA_URL = '/media/'
> 
> And my TEMPLATE includes:
> 
> <form action="" method="post">{% csrf_token %}
>     <enctype = 'multipart/form-data'></enctype>
>     <css = {'all': ('/media/css/main.css',)}></css>
> {{ form }}
> <input type = 'submit' value = 'Upload'/>
> </form>
> 
> Any suggestions much appreciated.
> 
> Bob
> 
-- 
Matías Aguirre <[email protected]>

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

Reply via email to