title: MultiValueDictKeyError at / django
body: <p>I am learning django after I just learned flask. I had a project I had to do in flask and now have same project in django. I went though with same code and "converted" it over. Its throwing an error of MultiValueDictKeyError at /farm.  If someone could direct me in which way to work</p>
  
  <p>The full trace back is as follows </p>
  
  <p>Traceback:</p>
  
  <pre><code>File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\core\handlers\exception.py" in inner
    42.             response = get_response(request)
  
  File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\core\handlers\base.py" in _get_response
    187.                 response = self.process_exception_by_middleware(e, request)
  
  File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\core\handlers\base.py" in _get_response
    185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\project7\ningagold\apps\ninjagold\views.py" in building
    47.   if request.POST["building"] == "farm":
  
  File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\utils\datastructures.py" in __getitem__
    85.             raise MultiValueDictKeyError(repr(key))
  
  Exception Type: MultiValueDictKeyError at /farm
  Exception Value: "'building'"
  </code></pre>
  
  <p>HTML </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;script type="text/javascript" src='http://code.jquery.com/jquery-1.10.2.min.js'&gt;&lt;/script&gt; 
    &lt;script&gt;
    &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div&gt;&lt;P&gt;Farm&lt;/P&gt;&lt;form action="/farm" method="post"&gt;
     {% csrf_token %}
    &lt;input type="hidden" name="building" value="farm" /&gt;
    &lt;input type="submit" value="Find Gold!"/&gt;
  &lt;/form&gt; &lt;/div&gt;
  &lt;div&gt;&lt;p&gt;Cave&lt;/p&gt;&lt;form action="/farm" method="post"&gt;
    {% csrf_token %}
    &lt;input type="hidden" name="building" value="cave" /&gt;
    &lt;input type="submit" value="Find Gold!"/&gt;
  &lt;/form&gt; &lt;/div&gt;
  &lt;div&gt;&lt;p&gt;House&lt;/p&gt;&lt;form action="/farm" method="post"&gt;
    {% csrf_token %}
    &lt;input type="hidden" name="building" value="house" /&gt;
    &lt;input type="submit" value="Find Gold!"/&gt;
  &lt;/form&gt; &lt;/div&gt;
  &lt;div&gt;&lt;p&gt;Casino&lt;/p&gt;&lt;form action="/farm" method="post"&gt;
    {% csrf_token %}
    &lt;input type="hidden" name="building" value="casino" /&gt;
    &lt;input type="submit" value="Find Gold!"/&gt;
  &lt;/form&gt; &lt;/div&gt;
  &lt;div&gt;&lt;p&gt;
  &lt;/p&gt;&lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.shortcuts import render, redirect, HttpResponse
  import random
  import string
  
  def index(request):
      return render(request, 'ninjagold/index.html')
  
  def building(request):
      if request.method == ['POST']:
          try:
              request.session['farmprint'] += ""
          except Exception:
              request.session['farmprint'] = ""
          try:
              request.session['caveprint'] += ""
          except Exception:
              request.session['caveprint'] = ""
          try:
              request.session['houseprint'] += ""
          except Exception:
              request.session['houseprint'] = ""
          try:
              request.session['casinoprint'] += ""
          except Exception:
              request.session['casinoprint'] = ""
      request.session['farm'] = 0
      request.session['cave'] = 0
      request.session['house'] = 0
      request.session['casino'] = 0
      if 'gold' not in request.session:
          request.session['gold'] = 0
      if request.POST["building"] == "farm":
          request.session['farm'] = random.randint(10, 20)
          print request.session['farm']
      elif request.POST["building"] == "cave":
          request.session['cave'] = random.randint(5, 10)
          print request.session['cave']
      elif request.POST["building"] == "house":
          request.session['house'] = random.randint(2, 5)
          print request.session['house']
      elif request.POST["building"] == "casino":
          request.session['casino'] = random.randint(-50, 50)
          print request.session['casino']
      if request.POST["building"] == "farm":
          request.session['farmprint'] += 'Earned' +str(request.session['farm']) + 'golds from the farm!\n'
  
      if request.POST["building"] == "cave":
          request.session['farmprint'] += "Earned" +str(request.session['cave']) + 'golds from the cave!\n'    
      if request.POST["building"] == "house":
          sessrequest.sessionion['farmprint'] += "Earned" +str(request.session['house']) + 'golds from the house\n'
      if request.POST["building"] == "casino":
          if request.session['casino'] &gt; 0:
              request.session['farmprint'] += "Earned" +str(request.session['casino']) + 'golds from the casino\n'    
      if request.POST["building"] == "casino":
          if request.session['casino'] &lt; 0:
              request.session['farmprint'] += "Earned" +str(request.session['casino']) + 'golds from the casino\n'    
          return render(request.session, 'ninjagold/index.html')
      else:
          return render(request.session, 'ninjagold/index.html')
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>from django.conf.urls import url
  from . import views
  from django.template import RequestContext
  
  urlpatterns = [
      url(r'^$', views.index),
      url(r'^farm$', views.building)
  ]
  </code></pre>