title: django request.session.user in template
body: <p>I am trying to use a custom User model and upon sign_in, I want to redirect the user to the homepage with the current user's information in the session. I ran the app in debug mode  and checked session information in chrome dev tools. It looks like everything is set as required, but the template code is not able to read session information correctly</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class User(AbstractBaseUser):
      name=models.CharField(max_length=255)
      email=models.CharField(max_length=255)
      slug = models.SlugField(unique=True, blank=True)
      .....
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def sign_in(request):
      user=None
      # import pdb; pdb.set_trace();
      if request.method=='POST':
          form=SigninForm(request.POST)
          if form.is_valid():
              results=User.objects.filter(email=form.cleaned_data['email'])
              if len(results) == 1:
                  if results[0].check_password(form.cleaned_data['password']):
                      request.session['user'] = results[0].pk
                      request.user=results[0]
                      return HttpResponseRedirect('/')
                  else:
                  .........
  </code></pre>
  
  <p><strong>Template</strong></p>
  
  <pre><code>    {% if user %} &lt;!-- I have also tried request.session.user !&gt;
        &lt;li&gt;&lt;a href="{% url 'sign_out' %}"&gt;Logout&lt;/a&gt;&lt;/li&gt;
      {% else %}
        &lt;li&gt;&lt;a href="{% url 'sign_in' %}"&gt;Login&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="{% url 'register' %}"&gt;Register&lt;/a&gt;&lt;/li&gt;
      {% endif %}
  </code></pre>
  
  <p><strong>Debug session</strong>.</p>
  
  <pre><code>&gt;&gt;&gt; from django.test import Client
  &gt;&gt;&gt; resp=Client().post('/sign_in/',{'email':'another@user.com','password':'anotherpassword2'})
  &gt; .../account/views.py(10)sign_in()
  -&gt; if request.method=='POST':
  ...
  -&gt; if len(results) == 1:
  (Pdb) n
  &gt; .../account/views.py(15)sign_in()
  -&gt; if results[0].check_password(form.cleaned_data['password']):
  (Pdb) n
  &gt; .../account/views.py(16)sign_in()
  -&gt; request.session['user'] = results[0].pk
  (Pdb) n
  &gt; .../account/views.py(17)sign_in()
  -&gt; request.user=results[0]
  (Pdb) n
  &gt; .../account/views.py(18)sign_in()
  -&gt; return HttpResponseRedirect('/')
  (Pdb) request.session.user
  *** AttributeError: 'SessionStore' object has no attribute 'user'
  (Pdb) request.session['user']
  9
  (Pdb) user
  (Pdb)
  </code></pre>
  
  <p>I also noticed that the session has some information, and this is what I get when I decode the info. </p>
  
  <pre><code>&gt;&gt;&gt; from django.contrib.sessions.models import Session
  &gt;&gt;&gt; sess = Session.objects.get(pk='XXXX')
  &gt;&gt;&gt; print(sess.session_data)
  .....
  &gt;&gt;&gt; print(sess.get_decoded())
  {u'_auth_user_hash': u'XXXXX', u'_auth_user_backend': u'django.contrib.auth.backends.ModelBackend', u'_auth_user_id': 1, u'user': 9}
  
  &gt;&gt;&gt; from django_project import settings
  &gt;&gt;&gt; settings.AUTH_USER_MODEL
  'account.User'
  </code></pre>