On Jan 9, 11:06 am, scelerat <jemenfi...@gmail.com> wrote: > Hi, I'm new to Django and am trying to figure out how to make > authentication work in any view. > > First off, I have a base template which has a conditional like this: > > {% if user.is_authenticated %} > Yay! > {% else %} > Boo. > {% endif %] > > In an accounts/urls.py, I add a line like this: > > urlpatterns = patterns('', > (r'^login/$', 'django.contrib.auth.views.login'), > (r'^logout/$', 'django.contrib.auth.views.logout'), > ) > > I copied the form from the Djangoprojects page on user authentication > into a registration/login.html template. > > When visiting accounts/login for the first time, I get 'Boo.' but if I > login and return to this login page, I get 'Yay.' > > If I go to any other view (all of them use the same base template), I > only get 'Boo.' > > I looked through django.contrib.auth.views.login, and couldn't find a > 'user' variable actually being set. Is this magic? How do I get the > magic to work for all my views?
If you use RequestContext and have the settings in your TEMPLATE_CONTEXT_PROCESSORS, then the user variable will be available for use in your templates. Check out: http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~----------~----~----~----~------~----~------~--~---