title: MultiValueDictKeyError in sending an attachment
body: <pre><code>&lt;script type="text/template" id="_escalation-container"&gt;
      &lt;div class="response-container"&gt;
          &lt;form action="" class="escalation-form" enctype="multipart/form-data"&gt;{% csrf_token %}
                  &lt;a href="#" class="add-scripted-message"&gt;{% trans "Add Message" %}&lt;/a&gt;
              &lt;/div&gt;
              &lt;div class="sub-content-footer" style="margin-top: 10px;"&gt;
                  &lt;input id="file" type="file" name="file"/&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>I look at <a href="https://docs.djangoproject.com/en/1.9/topics/http/file-uploads/" rel="nofollow">Django official documentation</a> and tried to do what is written there.</p>
  
  <p>View.py:</p>
  
  <pre><code>if request.POST:
      form = EscalationForm(request.POST, request.FILES)
      if form.is_valid():
          escalation_message = form.save(commit=False)
          handle_uploaded_file(request.FILES['file'])
          escalation_message.save()
  </code></pre>
  
  <p>And handle_uploaded_file is exactly the same;</p>
  
  <pre><code>def handle_uploaded_file(f):
      with open('some/file/name.txt', 'wb+') as destination:
          for chunk in f.chunks():
              destination.write(chunk)
  </code></pre>
  
  <p>EscalationForm.py:</p>
  
  <pre><code>class EscalationForm(forms.ModelForm):
      class Meta:
          model = EscalationMessage
  </code></pre>
  
  <p>and my model is:</p>
  
  <pre><code>class EscalationMessage(models.Model):
      file = models.FileField(null=True, blank=True, upload_to='.')
  </code></pre>
  
  <p>Also, I added these into my settings.py;</p>
  
  <pre><code>FILE_UPLOAD_HANDLERS = [
      "django.core.files.uploadhandler.MemoryFileUploadHandler",
      "django.core.files.uploadhandler.TemporaryFileUploadHandler"
  ]
  </code></pre>
  
  <p>However when I tried to send attachment it gave</p>
  
  <pre><code>File "/Users/mk/Documents/interaction/views.py", line 169, in create_escalation_message
      escalation_message.file = EscalationMessage(file=request.FILES['file'])
    File "/Users/mk/Documents/venvs/lib/python2.7/site-packages/django/utils/datastructures.py", line 322, in __getitem__
      raise MultiValueDictKeyError(repr(key))
  MultiValueDictKeyError: "'file'"
  </code></pre>
  
  <p>I am new in web development and I am writing a mini-demo. I was trying to send a message with an attachment and I searched an example however, it gave this error. Do you have any idea about the error? </p>
  
  <p>Thank you</p>