How to access the user profile in a Django template?

Swaroop C H picture Swaroop C H · Jan 7, 2009 · Viewed 51.3k times · Source

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?

Answer

AdamKG picture AdamKG · Jan 7, 2009

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