How to access the user profile in a Django template?


Question

I'm storing some additional per-user information using the AUTH_PROFILE_MODULE.

We can access the user in a Django template using {{ request.user }} but how do we access fields in the profile since the profile is only accessible via a function user.get_profile() ?

Is it really required to explicitly pass the profile into the template every time?

1
84
5/9/2016 8:09:59 AM

Accepted Answer

Use {{ request.user.get_profile.whatever }}. Django's templating language automatically calls things that are callable - in this case, the .get_profile() method.

131
1/7/2009 9:24:09 PM

Not sure why it's different for me, but I need to use {{user}} rather than {{request.user}}.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon