Access user data via Django template

Asked

Viewed 66 times

0

I have the user model that I extended from the Django standard

class TradingUser(User):
    avatar = models.ImageField(upload_to='images/', default='images/none.jpg')

Only when I try to access this avatar image via template

<img src=" {{ user.avatar }}">

It returns empty, I believe the Django user is as "User" and not as "Tradinguser". But when changing in Settings.py several errors occurred.

1 answer

1


In this situation, you need to use Trandinguser in the template as well. Example:

<img src="{{request.user.tradinguser.avatar.url}}">
  • Damn, that simple, as I didn’t think of it before. Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.