title: Getting KeyError in request.session
body: <p>Here is my code for using session in Django.  Everything seems fine but getting KeyError at /addfixeddeposit/</p>
  
  <blockquote>
    <p><strong>views.py</strong></p>
  </blockquote>
  
  <pre><code>def anotherpage(request, account_number):
      form = FixedDepositForm()
      context = {'form' : form}
      request.session['account_number'] = account_number
      return render(request, 'bankmanagement/another_page.html', context)
  
  def addfixeddeposit(request):
      if request.method == "POST":
          var = request.session['account_number']
          print(var)
          form = FixedDepositForm(request.POST)
          if form.is_valid:
              acc = Account.objects.get(pk = var)
              tenure = request.POST['tenure']
              rate = reuquest.POST['rate']
              new_fixed = FixedDeposit(account_number = acc, tenure = tenure, rate = rate)
              new_fixed.save()
              del request.session['account_number']
              return redirect('behome')
      return redirect('behome')
  </code></pre>
  
  <p>It's the html page in which I'm using session value. And then in addfixeddeposit in views.py</p>
  
  <blockquote>
    <p>another_page.html</p>
  </blockquote>
  
  <pre><code>&lt;form method="POST" action="{% url 'addfixeddeposit' %}"&gt;
                  {% csrf_token %}
                  &lt;div class="form-field"&gt;
                      &lt;table&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&lt;label for="accountnumfield" class="label--required"&gt;Account Number&lt;/label&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;label id="accountnumfield"&gt;{{ request.session['account_number'] }} &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&lt;label for="tenure" class="label--required"&gt;Tenure&lt;/label&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;span id='tenure'&gt;{{ form.tenure }}&lt;/span&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&lt;label for="rate" class="label--required"&gt;Rate&lt;/label&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;span id='rate'&gt;{{ form.rate }}&lt;/span&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/div&gt;
                  &lt;div class="form-buttons"&gt;
                      &lt;button type="submit" class="a-btn--filled"&gt;Add&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
  </code></pre>