I have a site on which I'm including a userBox with some data shown for each logged user (your name, avatar etc). From what I already know about django it seems obvious, that I should add query for user to context processor (so that I can use {{user}} variable in this included userBox ). But while using django-lfs shop I've noticed, that it's templates are using {{ user }} variable which is nowhere added to context processors nor template tags. Is there any other way to obtain user in my template than those 2 ?
A:
It's added by
django.contrib.auth.context_processors.auth
And the answer for the question is: if you need something to be in every template, you should use context_processor.
Dmitry Shevchenko
2010-05-21 10:14:43
ok but will using {{user}} from auth context processor allow me to include avatar of user or can I only check some basic parameters like .is_authenticated etc ?
sasquatch90
2010-05-21 10:26:42
for avatar you probably have some profile model right? use http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.models.User.get_profile to get it. Also you can just write your own processor, which'll put profile into context
Dmitry Shevchenko
2010-05-21 14:15:11
A:
using additional user data in your templates is easy:
{{ user.get_profile.foobar }}
where foobar is one of your profile's fields.
But make sure to have set AUTH_PROFILE_MODULE = 'yourprofileapp.YourProfileModel'
in settings.py
.
For more info see http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
mawimawi
2010-05-21 11:01:28