How to access the user profile in a Django template?

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

Use {{ request.user. Get_profile. Whatever }}.

Django's templating language automatically calls things that are callable - in this case, the . Get_profile() method.

1 +1: Beat me by 3 seconds! – S. Lott Jan 7 '09 at 21:24 Very cool.

Didn't know that it'll "call a callable" implicitly. – Swaroop C H Jan 7 '09 at 22:12 3 See docs.djangoproject. Com/en/dev/topics/templates/#variables The rules are very cool.

– S. Lott Jan 7 '09 at 22:14.

Yes it is possible to access profile from template using request.user. Get_profile However there is a small caveat: not all users will have profiles, which was in my case with admin users. So calling directly {{ request.user.

Get_profile. Whatever }} from the template will cause an error in such cases. If you are sure all your users always have profiles it is safe to call from template, otherwise call get_profile() from within try-except block in your view and pass it to the template.

It's try-except ;) – Vasil Mar 19 '09 at 16:09 :) yep, thanks, fixed it – umnik700 Mar 19 '09 at 16:48 This answer is misleading - I haven't tested {{ request.user. Get_profile. Whatever }}, but {{ request.user.

Get_profile }} will work and can be used to check whether a profile exists or not in current versions. See docs.djangoproject. Com/en/dev/ref/templates/api/… .

There is a note that that will change in the development version, though, see the paragraph above the one I linked to. – tkolar Jan 16 at 9:45 @tkolar, what exactly is misleading here? If user doesn't have a profile and you are calling get_profile.

Something that will cause an error. – umnik700 Feb 22 at 18:13.

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

1 The docs say (docs.djangoproject. Com/en/dev/topics/auth/…) that you can access the user simply by {{user}}, as you say. – Xiong Chiamiov Feb 2 '10 at 2:48.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions