title: Django login button turned to be logout after user logged in
body: <p>I want to create a button which can switch between login/out</p>
  
  <p>The button part on home.html:</p>
  
  <pre><code> &lt;li class="nav-item text-white"&gt;
       {% if request.user.is_authenticated %}
          &lt;a class="nav-link text-black font-weight-bold" href="{% url 'home' %}"&gt;Logout&lt;/a&gt;
       {% else %}
          &lt;a class="nav-link text-black font-weight-bold" href="{% url 'home' %}"&gt;Login&lt;/a&gt;
       {% endif %}
   &lt;/li&gt;
  </code></pre>
  
  <p>But I have no idea how to set with my views.py as it only show logout on home.html</p>
  
  <pre><code>def login_views(request):
    next = request.GET.get('next')
    form = UserLoginForm(request.POST or None)
    if form.is_valid():
      username = form.cleaned_data.get('username')
      password = form.cleaned_data.get('password')
      user = authenticate(username=username, password=password)
      login(request, user)
      if next:
          return redirect(next)
      return redirect('/')
      context = {
      'form': form,
        }
  
  return render(request, "login.html", context)
  
  
  def home(request):
     return render(request, 'home.html')
  </code></pre>