title: Django 1.6: Redirect to last page after login
body: <p>I want my user to be redirected to the last page after successfully logging in. But the user is redirected to the index page</p>
  
  <p>this is what I've in my header</p>
  
  <pre><code>  &lt;li&gt;&lt;a href="/login"&gt;Login&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>here is the login form</p>
  
  <pre><code>&lt;form method="post" action="{% url 'django.contrib.auth.views.login'  %}" &gt;
          {% if form.errors %}
            &lt;p&gt;Your username and password don't match our records. Please try again.&lt;/p&gt;
          {% endif %}
          &lt;div class="login"&gt;
         &lt;h1&gt; LOG IN &lt;/h1&gt;
            &lt;input type="text" class="form-control" id="username" placeholder="Email" name="username"&gt;
           &lt;input type="password" class="form-control" id="inputPassword" placeholder="Password" name="password"&gt;
  
            &lt;button class="btn btn-primary" type="submit" name="submit" id="ss-submit"&gt;LOG IN&lt;/button&gt;
            &lt;input type="hidden" name="next" value="{{ next }}" /&gt;
            &lt;!-- &lt;a href="/forgotpassword"&gt;Forgot your password?&lt;/a&gt; --&gt;
  
             &lt;p&gt;Don't have an account? &lt;a href="/signup"&gt;Sign up&lt;/a&gt;&lt;/p&gt;
  
          &lt;/div&gt;
          &lt;!-- End Log In --&gt;
            {% csrf_token %}
        &lt;/form&gt;
  </code></pre>
  
  <p>Here is the login</p>
  
  <pre><code>url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'meddy1/login.html'}, name="login"),
  </code></pre>
  
  <p>here is a template</p>
  
  <pre><code>def dentists(request):
      d = getVariables(request)
      doctors = Doctor.objects.all().order_by('-likes')
      paginator = Paginator(doctors, 20) #Show 20 doctors per page
      page =  page = request.GET.get('page')
      try:
          doctors = paginator.page(page)
      except PageNotAnInteger:
          doctors = paginator.page(1)
      except EmptyPage:
          doctors = paginator.page(paginator.num_pages)
      d['doctors'] = doctors
      d['paginator'] = paginator
      return render_to_response('meddy1/dentists.html',d)
  </code></pre>