title: Django MultiValueDictKeyError
body: <p>This is the error:</p>
  
  <pre><code>MultiValueDictKeyError at /add_city/
  "Key 'city_image' not found in &lt;MultiValueDict: {}&gt;"
  </code></pre>
  
  <p>This is the POST info:</p>
  
  <pre><code>Variable                 Value
  country                  u'Bahrain'
  csrfmiddlewaretoken      u'NyuznsyqteRfmgkUC9W0TpZeuuU99WMZ'
  name                     u'vv'
  city_image               u'Tuna_8.jpg'
  </code></pre>
  
  <p>This is the view:</p>
  
  <pre><code>class addCity(View):
      def get(self, request, *args, **kwargs):
          countries = Country.objects.all()
          return render_to_response('addCity.html', {'countries':countries}, RequestContext(request))
  
      def post(self, request, *args, **kwargs):
          name    = request.POST['name']
          country = Country.objects.get(name=request.POST['country'])
          image   = request.FILES['city_image']
          city    = City.objects.create(name=name, country=country, image= image)
          return HttpResponse("success")
  </code></pre>
  
  <p>This is the <code>QueryDict</code> when i <code>print request.POST</code>:</p>
  
  <pre><code>&lt;QueryDict: {u'country': [u'Bahrain'], u'csrfmiddlewaretoken': [u'NyuznsyqteRfmgkUC9W0TpZeuuU99WMZ'], u'name': [u'bb'], u'city_image': [u'user.png']}&gt;
  </code></pre>
  
  <p>As you can see, the key 'city_image' is clearly present in the QueryDict, then why am i getting an error saying <code>key'city_image</code>' not found?</p>
  
  <p>This is my html file. </p>
  
  <pre><code>&lt;form method="POST" enctype="multi-part/formdata"&gt;{% csrf_token %}
      &lt;input type="text" name = "name" class="form-control" placeholder="City name" autofocus&gt;
      &lt;div class="control-group"&gt;
          &lt;label for="country" class="control-label" style="margin:15px"&gt;&lt;/label&gt;
          &lt;div class="controls"&gt;
              &lt;select name="country" id="country" class="form-control"&gt;
                  &lt;option value=""&gt;Select Country&lt;/option&gt;
                  {% for country in countries %}
                      &lt;option value="{{country}}"&gt;{{country}}&lt;/option&gt;
                  {% endfor %}
              &lt;/select&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;input name ="city_image" type="file" style="margin:15px"&gt;
      &lt;input button class="btn btn-lg btn-primary btn-block" id = "create_city_button" type="submit" value = "Create City"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is the traceback:</p>
  
  <pre><code>Traceback:
  File "/home/hammad/virt_env/virt1/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
    115.                         response = callback(request, *callback_args, **callback_kwargs)
  File "/home/hammad/virt_env/virt1/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
    68.             return self.dispatch(request, *args, **kwargs)
  File "/home/hammad/virt_env/virt1/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
    86.         return handler(request, *args, **kwargs)
  File "/home/hammad/virt_env/virt1/gccFishing/Locations/views.py" in post
    388.      image = request.FILES['city_image']
  File "/home/hammad/virt_env/virt1/local/lib/python2.7/site-packages/django/utils/datastructures.py" in __getitem__
    295.             raise MultiValueDictKeyError("Key %r not found in %r" % (key, self))
  
  Exception Type: MultiValueDictKeyError at /add_city/
  Exception Value: "Key 'city_image' not found in &lt;MultiValueDict: {}&gt;"
  </code></pre>