title: django 3.1 user not staying logged in
body: <p>So, I have a django 3.1 project and a Foo app that is going to have a user login, but I am running into the problem where users will not retain a logged in status after any additional requests. the code is similar to that below, but pretend that all relevant imports are made that are otherwise absent.</p>
  <p>views.py</p>
  <pre><code>from django.shortcuts import render
  from django.contrib import auth
  from django.http import HttpResponseRedirect
  def login(request):
      if request.method == &quot;POST&quot;:
          username = request.POST['username']
          password = request.POST['password']
          user = auth.authenticate(request, username=username, password=password)
          if user is not None:
              auth.login(request, user)
              if request.user.is_authenticated:
                  return HttpResponseRedirect(reverse(&quot;Foo:stays_loggedin_check&quot;))
              return render(request, template_name=&quot;Foo/loginfailed.html&quot;)
      return render(request, template_name=&quot;Foo/login.html&quot;)
  def stays_loggedin_check(request):
      if request.user.is_authenticated:
          return render(request, template_name=&quot;Foo/staysloggedin.html&quot;)
      return render(request, template_name=&quot;Foo/weirdly_doesnt_stay_logged_in_despite_documentaion.html&quot;)
  </code></pre>
  <p>urls.py
  from django.urls import path</p>
  <pre><code>from . import views
  app_name = &quot;Foo&quot;
  
  urlpatterns = [
      path(&quot;login&quot;, views.login, name=&quot;login&quot;),
      path(&quot;shouldnt_need_to_do_this&quot;, views.stays_loggedin_check, name=&quot;stays_loggedin_check&quot;),
  ]
  </code></pre>
  <p>When one fills out the login form at Foo/login.html incorrectly it, as expected, renders the page Foo/loginfailed.html. but when filled out correctly this form returns Foo/weirdly_doesnt_stay_logged_in_despite_documentaion.html. Is there a way to model behavior to be in line with django documentation where this will return Foo/staysloggedin.html instead?</p>