Kev Dwyer wrote: > On Sun, 14 Feb 2010 01:19:41 -0800, Achim Domma wrote: > > >> Hi, >> >> depending on if a user is logged in or not, I want to display a "login" >> form or a "logout" button. I tried to use this code snippet: >> >> http://docs.djangoproject.com/en/1.1/topics/auth/#id6 >> >> If I render my view using render_to_response("myTemplate.html") the user >> variable is empty. If I use >> render_to_response("myTemplate.html",context_instance=RequestContext(request)) >> I get the correct user and can display the username. But >> is_authenticated still always returns false!? Any hint what I might be >> doing wrong? >> >> According to the documentation >> "context_instance=RequestContext(request)" should only be required when >> passing a additional data dictionary to render_to_response. As passing >> data to a view and checking if the user is logged in should be something >> quite common, this sounds strange to me!? >> >> I want to display the user information / status in my master template, >> so having to pass a RequestContext into the template from each view >> would be very tedious. Feels like I'm on a complete wrong way!? >> >> Any hint would be very appreciated! >> >> cheers, >> Achim >> > > Hello Achim, > > It's difficult to tell why is_authenticated returns false for you, but > assuming there aren't any typos in your template then you need to check > that your views are working correctly, particularly that authentication > are not "lost" by forgetting to pass them to one of your views. > > Passing a RequestContext to your templates is the correct way to give your > templates access to authentication information. It seems cumbersome > while your changing all your render_to_response calls but it doesn't > need any maintenance after that. > > Cheers, > > Kev > > did you put 'django.core.context_processors.request' into your TEMPLATE_CONTEXT_PROCESSORS in your settings.py?
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.