title: request.FILES always empty on file upload
body: <p>I am totally stumped on this, and must be doing something incredibly stupid. I am trying to simply upload a file on a Django project. The problem seems to be that NO form data is getting passed through to the server--only the csrf token. I am running Django 1.5.1, python 2.7, virtualenv, on a Mac, and using the built-in Django development server.</p>
  
  <p>My HTML form is:</p>
  
  <pre><code>{% load url from future %}
  
  &lt;form enctype="multipart/form-data" method="POST" action="{% url 'showreport' %}"&gt;
      {% csrf_token %}
      &lt;label&gt;Upload grade csv file: &lt;/label&gt;
      &lt;input type="hidden" id="testing" value="maybe" /&gt;
      &lt;input type="file" id="grade_csv" /&gt;
      &lt;input type="submit" value="Generate Report" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My model:</p>
  
  <pre><code>from django.db import models
  
  class Document(models.Model):
  file = models.FileField(upload_to='/media/', blank=True, null=True)
  </code></pre>
  
  <p>My forms.py:</p>
  
  <pre><code>from django import forms
  from .models import Document
  
  class DocumentForm(forms.Form):
  """
  to handle uploading grades csv file
  """
  class Meta:
      models = Document
  </code></pre>
  
  <p>My views.py:</p>
  
  <pre><code>def report(request):
  """
  Process the CSV file to remove inactive students
  Manipulate to get right JSON format
  Chart the results
  """
  if request.method == 'POST':
      form = DocumentForm( request.POST, request.FILES )
      if form.is_valid():
          newfile = Document( file = request.FILES['file'] )
          newfile.save()
  
          classdata = {}
          studentdata = {}
  
          return render( request, 'report/showreport.html', { 'classdata': classdata, 'studentdata': studentdata } )
  else:
      form = UploadFileForm()
  
  return render( request, 'report/index.html', { 'form': form })
  </code></pre>
  
  <p>I have spent several hours searching for a solution, but nothing seems to work. <a href="https://docs.djangoproject.com/en/dev/topics/http/file-uploads/" rel="noreferrer">I have the enctype set correctly</a> (I think), <a href="https://stackoverflow.com/questions/7509308/form-not-posting-in-django">I am using input type 'submit' for the form</a>, and <a href="https://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form" rel="noreferrer">I am binding the form data to my model</a> (doesn't matter, since request.FILES is empty). I also tried using a direct url in my form action (action='/report/showreport/') per <a href="https://code.djangoproject.com/wiki/NewbieMistakes" rel="noreferrer">this Django newbie page</a>, but that didn't make a difference. As far as I can tell, there are no other scripts binding to the form submit action and overriding the default action.</p>
  
  <p>I also realize that the code above should most likley be request.FILES['grades_csv'] to match the form's input id...yet that also doesn't matter yet, since request.FILES is empty.</p>
  
  <p>In trying to debug, I have set a pdb trace right before the if request.method == "POST" in my view. Using the console, I can see that my request.POST does not include my hidden "testing" input, and that request.FILES is empty. When I run this in a browser, it just returns me to my form page, essentially saying my form is invalid. My pdb results are here:</p>
  
  <pre><code>(Pdb) request.FILES
  (Pdb) &lt;MultiValueDict: {}&gt;
  (Pdb) request.POST['testing']
  (Pdb) *** MultiValueDictKeyError: "Key 'testing' not found in &lt;QueryDict: {u'csrfmiddlewaretoken': [u'0tGCChxa3Po619dCi114Sb9jmWRt82aj']}&gt;"
  (Pdb) request.POST
  &lt;QueryDict: {u'csrfmiddlewaretoken': [u'0tGCChxa3Po619dCi114Sb9jmWRt82aj']}&gt;
  </code></pre>
  
  <p>If I try to access request.FILES in my views.py without checking if the form is valid, I get this error:</p>
  
  <pre><code>"Key 'file' not found in &lt;MultiValueDict: {}&gt;"
  </code></pre>
  
  <p>I am stumped and appreciate any help on why I cannot get this to work--it seems like it should be simple. I can manually create and write to files within my project directory using pdb, so I don't think permissions are the problem...the problem is in the form?</p>