Unable to access UserProfile model fields in templates in Django

0 votes

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() ?

Nov 12, 2020 in Python by Niroj
• 82,720 points
75 views

1 answer to this question.

0 votes

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

answered Nov 13, 2020 by Gitika
• 65,870 points

Related Questions In Python

0 votes
1 answer

How to extend the User model with custom fields in Django?

Hello @kartik, Define an object manager for your ...READ MORE

answered Aug 3, 2020 in Python by Niroj
• 82,720 points
798 views
0 votes
1 answer

How to get all related Django model objects in Python?

This actually gives you the property names ...READ MORE

answered Nov 14, 2018 in Python by Nymeria
• 3,520 points

edited Dec 18, 2018 by Nymeria 4,152 views
0 votes
1 answer

How to Specify a mySQL ENUM in a Django model?

Hello @kartik, You can follow this snippet below: MAYBECHOICE ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,720 points
262 views
0 votes
1 answer
0 votes
1 answer

Unable to create a project in django.

I think u didn't install Django. python -m ...READ MORE

answered Nov 12, 2020 in Python by Gitika
• 65,870 points
79 views
0 votes
1 answer

How to access a module written in Python from C?

Hey, @Roshni: You can access a module written ...READ MORE

answered Jun 26, 2020 in Python by Gitika
• 65,870 points
317 views