Totally fixed me up. Thanks! On Mar 19, 9:33 am, "James Bennett" <[EMAIL PROTECTED]> wrote: > On 3/19/07, mediumgrade <[EMAIL PROTECTED]> wrote: > > > I am not sure what the difference is between RequestContext and > > Context (I am still fairly new to Django and Python). > > RequestContext automatically adds some extra variables to the context > of every template that uses it; exactly which variables depends on the > TEMPLATE_CONTEXT_PROCESSORS setting, but the default set includes a > variable called 'user', which lets you do things like '{% if > user.is_authenticated %}' in a template. > > To use it you'd want to do something like this: > > from django.template import RequestContext > > def home(request): > if not request.user.is_authenticated(): > return render_to_response('login_error.html', {}, > context_instance=RequestContext(request)) > else: > return render_to_response('index.html', {}, > context_instance=RequestContext(request)) > > And also note that Django will happily help you out with forcing > login; you could write the view like this: > > from django.template import RequestContext > from django.contrib.auth.decorators import login_required > > def home(request): > return render_to_response('index.html', {}, > context_instance=RequestContext(request)) > > home = login_required(home) > > The 'login_required' decorator will accomplish the same thing as your > manual authentication check -- if the user isn't logged in, it will > force them to log in and then go on to your view. > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of correct."
--~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---