title: Django Redirect to current page
body: <p>I am having troubles with the redirect to the same page user was on after logging in, no matter how hard I tried and read all the questions here. I think it is high time I showed folks out here my code so if you can point out mistake(s). Thanks.</p>
  
  <p>My login url (in base.html template):
  This is present on every page. Changes to logout once the user is logged in. I read that I have to pass a param for example 'next' like this: </p>
  
  <pre><code> &lt;a href="/login/?next={{request.path}}"&gt;Login&lt;/a&gt;
  </code></pre>
  
  <p>but,</p>
  
  <h2>*<em>The <code>{{request.path}}</code> is always empty. *</em></h2>
  
  <p>login view:</p>
  
  <pre><code>def mylogin(request):
      """login view"""
      try:
          redirect_to = request.GET.get('next', '/')
      except ValueError:
          redirect_to = "/"
  
  errors = ''
  t = loader.get_template('login.html')
  
  
  # check for POST data
  if request.method == 'POST':
      username = request.POST['username']
      password = request.POST['password']
      user = authenticate(username=username, password=password)
      if user is not None:
          if user.is_active:
              login(request, user)
              # Redirect to a success page.
              return HttpResponseRedirect(redirect_to)
          else:
              c = Context({
                  'errors':'disabled',
              })
              return HttpResponse("disabled")
      else:
          c = Context({
              'errors':'incorrect',
          })
          return HttpResponse(t.render(c))
  else:
      c = Context({
          'errors':None,
      })
      return HttpResponse(t.render(c))
  </code></pre>
  
  <hr>
  
  <p>The login form, in login.html template</p>
  
  <pre><code> &lt;form method="post" action="?next={{ redirect_to }}" &gt;
         &lt;p&gt;&lt;label for="username"&gt;Username&lt;/p&gt;
         &lt;p&gt;&lt;/label&gt;&lt;input type="text" name="username" value="" id="username" /&gt;&lt;/p&gt;
         &lt;p&gt;&lt;label for="password"&gt;Password&lt;/label&gt;&lt;/p&gt;
         &lt;p&gt;&lt;input type="password" name="password" value="" id="password" /&gt;&lt;/p&gt;
         &lt;p&gt;&lt;input type="submit" value="Login"&gt;&lt;/p&gt;
   &lt;/form&gt;
  </code></pre>