title: Redirecting Django built-in login View to a URL taking user's pk as argument
body: <p>I am trying to redirect to a URL taking user's pk as argument after successful log-in using Django's built-in login view.</p>
  
  <p>Instead of dynamic {{ next }} variable in my login.html I have a generic landing view of logged-in users;</p>
  
  <pre><code>&lt;input type="submit" value="login" /&gt;
  &lt;input type="hidden" name="next" value="{% url 'userredirect' %}" /&gt;
  </code></pre>
  
  <p>In my urls.py I have;</p>
  
  <pre><code>url(r'^users/', views.users, name='userredirect'),
  url(r'^(?P&lt;pk&gt;\d+)/', UserHome.as_view(), name='userhome'),
  </code></pre>
  
  <p>and in my views.py I have</p>
  
  <pre><code>@login_required
  def users(request):
      url = reverse('userhome', kwargs={'pk':request.user.id})
      return HttpResponseRedirect(url)
  </code></pre>
  
  <p>What I am doing here is redirect to a detail view that I have named <code>UserHome</code> on the user model after successful login using 2 redirects as I do not know of a way to redirect to <code>UserHome</code> directly (it takes user's pk as argument). It works and I indeed get redirected to the user's homepage when checking via the browser.</p>
  
  <p>Reference; </p>
  
  <p><a href="https://stackoverflow.com/questions/3441436/the-next-parameter-redirect-django-contrib-auth-login">The &quot;next&quot; parameter, redirect, django.contrib.auth.login</a></p>
  
  <p>But when running the below test</p>
  
  <pre><code>    def test_page_redirects_to_user_home_on_login(self):
      """
      Test to assure that the login page redirects to the user's
      home page
      """
      username = "someusername"
      password = "somepassword"
      user = User.objects.create_user(username=username,
                  password=password)
      user.save()
      response = self.client.post(reverse("userlogin"),
                                  {"username":username,
                                   "password":password},
                                  follow=True)
      assert response.path == self.client.get(reverse("userhome", 
                                                      kwargs={"pk":user.id}
                                                 )
                                         )
  </code></pre>
  
  <p>I get the below failure</p>
  
  <pre><code>AttributeError: 'HttpResponseNotFound' object has no attribute 'path'
  </code></pre>
  
  <p>It seems the test client gets no page. Would it be that I am using the <code>userredirect</code> view simply for redirecting and the client do not go ahead and get the <code>UserHome</code> class view to its context. </p>
  
  <p>I'm a newbie to Django/Python. Someone please sort this out for me :).</p>
  
  <p>I look forward either to a way where I can redirect directly from the template for <code>login</code> view to <code>UserHome</code> or a way to rewrite my test.</p>