title: Django redirect not working in authentication
body: <p>I am trying to authenticate a registered user . redirect is not working in my case. after clicking the login button it keep on showing the login page again. i want the user to go to home page upon the successful login. Here are my files.</p>
  <p>views.py</p>
  <pre><code>from django.shortcuts import render, redirect
  from django.http import HttpResponseRedirect
  from django.contrib import messages
  from django.contrib.auth import authenticate, login, logout
  
  def register_new_a(request):
      saved = False
      if request.method == &quot;POST&quot;:
      # take whatever is posted to the Details Form
          form = DetailsForm(request.POST)
          if form.is_valid():
              form.save()
              messages.success(request, 'Your account details have been saved!')
              return HttpResponseRedirect('/register_new_a?saved=True')
      else:
          form = DetailsForm()
          if 'saved' in request.GET:  # sends saved var in GET request
             saved = True
  
      return render(request, 'register1.html', {'form': form, 'saved': saved})
  
  def loginUser(request):
      if request.method == &quot;POST&quot;:
          username = request.POST.get('username')
          password = request.POST.get('password')
  
          user = authenticate(request, username=username, password=password)
          if user is not None:
          # at backend authenticated the credentials
              login(request, user)
              return redirect('home') # not working
      return render(request, 'login_a.html')
  </code></pre>
  <p>urls.py</p>
  <pre><code>from django.contrib import admin
  from django.urls import path
  from home import views
  
  urlpatterns = [
  path(&quot;&quot;, views.index, name='home'),
  path(&quot;login&quot;, views.loginUser, name='login'),
  path(&quot;logout&quot;, views.logoutUser, name='logout'),
  #path(&quot;register&quot;, views.register, name='register'),
  path(&quot;register_new_a&quot;, views.register_new_a, name='register_new_a'),
  path(&quot;register_new_b&quot;, views.register_new_b, name='register_new_b'),
  path(&quot;about&quot;, views.about, name='about'),
  ]
  </code></pre>
  <p>login_a.html</p>
  <pre><code>{% extends 'base.html'%}
  {% block title %}Login{% endblock title %}
  
  {% block body %}
  &lt;div class=&quot;container my-3&quot; &gt;
  &lt;h1 class=&quot;display-3&quot; align=&quot;center&quot;&gt;Login Here&lt;/h1&gt;
  &lt;br&gt;
  &lt;h1 class=&quot;display-6&quot; &gt;STEP 1: &lt;/h1&gt;
  
  &lt;form method=&quot;post&quot; action=&quot;&quot;&gt;
  {% csrf_token %}
  &lt;div class=&quot;mb-3&quot;&gt;
  &lt;label for=&quot;Username1&quot; class=&quot;form-label&quot; &gt;Username &lt;/label&gt;
  &lt;input type=&quot;username&quot;class=&quot;form-control&quot; name=&quot;username&quot;&gt;&lt;/input&gt;
  &lt;/div&gt;
  &lt;div class=&quot;mb-3&quot;&gt;
  &lt;label for=&quot;Password1&quot; class=&quot;form-label&quot;&gt;Password&lt;/label&gt;
  &lt;input type=&quot;password&quot; class=&quot;form-control&quot; id=&quot;Password1&quot; name=&quot;password&quot;&gt;
  &lt;/div&gt;
    New user? &lt;a href=&quot;register_new_a&quot;&gt;Register Here&lt;/a&gt;
  &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary float-end&quot; style=&quot;background: #0a9396&quot; &gt; Next&lt;/button&gt;
  
  &lt;/form&gt;
  
  &lt;/div&gt;
  {% endblock body %}
  </code></pre>
  <p>Any help would be appreciated.</p>