title: Using session in django
body: <p>I want to use session in django. Here is my code:</p>
  
  <p>view.py</p>
  
  <pre><code>def function(request):
      if request.method == 'POST' and request.is_ajax:
          action = request.POST['action']
  
          if action == 'check':
              if request.session.get('username', ''):
                  print 'yes'
                  print request.session['username']
              else:
                  print 'no'
                  request.session['username'] = 'John'
      return HttpResponse('')
  </code></pre>
  
  <p>The result of function always is <code>no</code>.
  How to fix it?</p>