I would use HttpresponseRedirect instead of render_to_response after login.
Try this:

def login(request):
  news_list = New.objects.all().order_by('-date')
  if request.method == 'POST':
    username = request.POST['username']
    password = request.POST['password']
    user = auth.authenticate(username=username, password=password)
    if user is not None:
          if user.is_active:
            auth.login(request,user)
            return HttpResponseRedirect('main.html', locals())
          else:
            # add some message to inform user, that he's not active
            # or redirect to somekind of error page
            return render_to_response('registration.html', locals())
  else:
     return render_to_response('registration.html', locals())

I'm using almost similar view in my project and there was no problem in 0.96
as well as in 1.0

Radovan


Robocop-2 wrote:
> 
> 
> Having looked through the archived posts, i found a similar problem
> that had found no solution:
> http://groups.google.com/group/django-users/browse_thread/thread/bf056018de75c6b5/12723e786ce0fa6e?lnk=gst&q=login#12723e786ce0fa6e
> 
> It looks like django is not actually logging my user in, or not
> creating a session.  I have a very simple snippet for login
> functionality pretty much lifted directly from the docs:
> 
> 
> from django.contrib.auth import logout, login, authenticate
> 
> def login(request):
>   news_list = New.objects.all().order_by('-date')
>   if request.method == 'POST':
>     username = request.POST['username']
>     password = request.POST['password']
>     user = auth.authenticate(username=username, password=password)
>     if user is not None:
>         if user.is_active:
>           auth.login(request,user)
>         return render_to_response('main.html', locals())
>     else:
>       return render_to_response('registration.html', locals())
> 
> settings.py:
> INSTALLED_APPS = (
>     'django.contrib.auth',
>     'django.contrib.contenttypes',
>     'django.contrib.sessions',
>     'django.contrib.sites',
>     'django.contrib.admin',
>     'intrinsic.site',
> )
> 
> When i was running this project under .96 i never had this issue.
> It's as if the auth.login line is somehow failing silently.  I've
> tested and am absolutely sure that the code does everything it should
> but that one auth.login line.  So because of this i can't get at the
> {{user}} variable in my templates.  Any help, or suggestions for
> debugging attempts would be great.
> > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/auth.login-problems-in-Django-1.0-tp19843181p19912456.html
Sent from the django-users mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to