views:

141

answers:

1

Hello, I am with some trouble in Django...

After login I am losing auth session for some pages. If I access "accounts/login/","accounts/logout/",""accounts/register/" the session always will be there, but if I access different page I cant access the user variable.

This is strange because I am using the same "base.html" for all pages and inside has the logic "if user.is_authenticated", how I said this condition is true just when I access pages that have "accounts" in the URL.

in the settings file I enabled theses three middleware:

MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', )

Thanks

+3  A: 

Just a guess here: are you including RequestContext in your context in the views that you cannot access user?

In other words, if you call generic views the RequestContext is automatically included but if you are using render_to_response() then you need to call it like this:

return render_to_response('template_name',
    { your context dict },
    context_instance=RequestContext(request))
Van Gale
+1 - to make life easier, use `render_to` from http://bitbucket.org/offline/django-annoying/wiki/Home
Dominic Rodger