tags:

views:

15

answers:

1

instead of User.

def myview(request):   
    return render_to_response('tmpl.html', {'user': User.objects.get(id=1})

works fine and passes User to template. But

def myview(request):   
    return render_to_response('tmpl.html', {}, context_instance=RequestContext(request))

with a context processor

def user(request):
    from django.contrib.auth.models import User
    return {'user': User.objects.get(id=1)}

passes AnonymousUser, so I can't get the variables I need :( What's wrong?

+1  A: 

Are you sure that your context processor is enabled in TEMPLATE_CONTEXT_PROCESSORS in settings.py?

More to the point, does it come before or after the built-in django.contrib.auth.context_processors.auth? If it's before, it will be overridden by that processor, which will redefine user as the actual logged-in user, or AnonymousUser if none.

Daniel Roseman
Solved. Just moved my context processor to the **end** of TEMPLATE_CONTEXT_PROCESSORS. Thanks
myfreeweb