title: How to store an object in django sessions framework
body: <p>I have an django and i am trying to store an object in django session varaible, and trying to access that in the redirected view, but its showing <code>keyerror</code>  as below</p>
  
  <pre><code>def payment(request):
      if request.method == 'POST':
          form = CardForm(request.POST)
          if form.is_valid():
              data = form.cleaned_data
              response = response_from_payment_gateway(data)
              request.session['response'] = response
              return HttpResponseRedirect(reverse('paygate:payment_success'))
      else:
          form = CardForm(initial={'number':'4242424242424242'})
      return render_to_response('payment_form.html',{'form': form})
  
  
  def PaymentSuccess(request):
      print request.session['response'],"=================&gt;"
      response = None
      return render_to_response("payment_success.html", {'response':response}, context_instance=RequestContext(request))
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre><code>Internal Server Error: /payment/success/
  Traceback (most recent call last):
    File "/home/Envs/app/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
      response = callback(request, *callback_args, **callback_kwargs)
    File "/home/user/virtualenvironment/apps/app/payment/views.py", line 120, in PaymentSuccess
      print request.session['response'],"=================&gt;"
    File "/home/Envs/app/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py", line 46, in __getitem__
      return self._session[key]
  KeyError: 'response'
  </code></pre>
  
  <p>So i am getting back a response object from the payment gateway that contains the transaction details, and i am trying to save that in <code>session framework variable</code> called <code>response</code> as above.</p>
  
  <p>And i am trying to access the variable called <code>response</code> in the redirected view <code>PaymentSuccess</code> as <code>request.session['response']</code>, and getting the above mentioned error.</p>
  
  <p>so how can we send/save the objects in the <code>sessions</code> in django ?</p>
  
  <p>In above the response object will be of the following form </p>
  
  <pre><code>{'status': 'SUCCESS', 'response': &lt;Charge charge id=ch_2OXdxxxxNVw at 0xb508e76cL&gt; JSON: {
    "amount": 100, 
    "amount_refunded": 0, 
    "balance_transaction": "txxxn_xxxxxxxxO", 
    "captured": true, 
   "currency": "usd", 
    "customer": null, 
    "description": null, 
  }}
  </code></pre>