title: Django login(request, user) don't put user in session?
body: <p>I can't seem to work out how to log in users in Django. I'm confused because the documentation tells you explicitely how to do it, but still somehow I must be making a mistake.</p>
  
  <p>The link
  <a href="https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.login" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.login</a>
  says
  "To log a user in, from a view, use login(). It takes an HttpRequest object and a User object. login() saves the user’s ID in the session, using Django’s session framework."</p>
  
  <p>So I have the following views.py:</p>
  
  <pre><code>def login_view(request):
      if request.method == 'GET':
          return render(request, 'app/login.htm')
      if request.method == 'POST':
          username = request.POST.get('username', '')
          password = request.POST.get('password', '')
          user = auth.authenticate(username=username, password=password)
          if user is None:
              return HttpResponseRedirect(reverse('error'))
          if not user.is_active:
              return HttpResponseRedirect(reverse('error'))
  
          # Correct password, and the user is marked "active"
          auth.login(request, user)
          # Redirect to a success page.
          return HttpResponseRedirect(reverse('home'))
  
  def home(request):
      contextdict = {}
      if request.session.user.is_authenticated():
          contextdict['username'] = request.session.user.username
      context = RequestContext(request, contextdict )
      return render(request, 'app/home.htm', context)
  </code></pre>
  
  <p>Now, by using print 'qqq' I know for a fact that 'is None' and 'not is_active' have been evaluated to True, and so auth.login is evaluated and the HttpResponseRedirect is returned. I expected everythin to go normally and the user to be logged in, and the user name to be passed as context in the home view. However, Django gives me the following error:</p>
  
  <pre><code>AttributeError at /app/home/
  'SessionStore' object has no attribute 'user'
  </code></pre>
  
  <p>Yeah, I have no idea what I'm doing.</p>