title: Conditional login redirect in Django
body: <p>I know about <code>LOGIN_REDIRECT_URL</code> and I know about </p>
  
  <pre><code>&lt;form action="?next={{ next|default:"/foo" }}" method="post"&gt;
  </code></pre>
  
  <p>in django-registration's login.html template. Here's what I want to happen:</p>
  
  <ul>
  <li><p>If a user logs in from the homepage,
  redirect them to a URL that contains
  their username (/lists/[username]).</p></li>
  <li><p>If a user logs in from any other
  page, return them to the page they
  were viewing.</p></li>
  </ul>
  
  <p>The way twitter.com handles this is to simply make the homepage go away for logged in users. I would consider doing that, and it would be pretty easy to solve, but my homepage still has useful stuff on it and I'm not sure I want it to go away for authenticated users. I'd rather redirect them. </p>
  
  <p>I was thinking I could do a conditional in settings.py where <code>LOGIN_REDIRECT_URL</code> is referenced, but the request object is not available in settings (so I can't access request.user.username to build the redirect). And obviously, I can't do it in django-registration's "default" parameter in the template because the username isn't known before login. </p>
  
  <p>What's the correct/best way to solve this? Thanks.</p>
  
  <p><strong>Update</strong>: Based on S. Lott's suggestion below, this is what I ended up using (in the homepage view):</p>
  
  <pre><code>if request.user.is_authenticated() and not request.session.get('homepage_redir'): 
      request.session['homepage_redir'] = True
      return HttpResponseRedirect(reverse('list_view',args=[request.user.username])) 
  </code></pre>
  
  <p>On the first login from homepage, the user is redirected to their personal page and a session variable is set. On subsequent requests for the homepage, the redirect does not occur (because the session var is detected). Code for redirecting logins from any other page is not affected.</p>