title: Django 1.2 session loss
body: <p>I've asked a similar question before, but I've done some more research and this iteration should be a bit different.  It seems as though several SO users have had an issue with registering and logging in users in a single view and it hasn't really been answered.   </p>
  
  <p>The issue is that I register, authenticate, and login a user in a single Django view.  For most users that's fine, but for other users, their subsequent request (they click a link on my site) returns an Anonymous User.  Somehow, the logged in user loses their session and is redirected to a page on my sit ethat doesn't require authentication. </p>
  
  <p>When they then log in via a pure login view (as opposed to the register + login view), the session data stays in tact.  The issue really seems to be registering and logging in a single view. </p>
  
  <p>See this post for the same issue:  <a href="https://stackoverflow.com/questions/1693726/problem-with-combined-authentication-login-view">https://stackoverflow.com/questions/1693726/problem-with-combined-authentication-login-view</a>. </p>
  
  <p>It has been suggested that this is potentially a threading issue.  I've also seen it suggested that it relates to the backend for caching session data. </p>
  
  <p>Any thoughts on what it really relates to?  I can't reproduce the error, which is really holding me back. </p>
  
  <p>EDIT--I should note that I'm using the default database backed sessions. </p>
  
  <p>Here is my register/login view </p>
  
  <pre><code>def splash_register(request):
    if request.session.get('beta'):
  
      if request.method=='POST':
          userform=MyUserCreationForm(request.POST)
          if userform.is_valid():
              #username of &lt;30 char is required by Django User model.  I'm storing username as a hash of user email 
  
              user=userform.save(commit=False)
              user.username=hash(user.email)
              user.save()
  
  
  
              username=user.username
              password=str(userform.cleaned_data['password'])
              user=auth.authenticate(username=username, password=password)
              if user is not None:
                  auth.login(request,user)
                  request.session['first_visit']=True
                  return HttpResponseRedirect("/")
              else:
                  return HttpResponseRedirect('/splash/register/')
          else:
              userform=MyUserCreationForm(request.POST)
              return render_to_response("website/splash_register.html", {'userform':userform}, context_instance=RequestContext(request))
      return render_to_response("website/splash_register.html", context_instance=RequestContext(request))     
  else:
      return HttpResponseRedirect('/splash/')        
  </code></pre>