djangodjango-staticfilesdjango-static

Is there a way to load avatar of each user using static method in Django?


I'm looping through each message which has a particular user which in intern as an image associated with it.

<img src="{{message.user.avatar.url}}" />

I want to convert it something like this (which I know is obviously very wrong)

<img src="{% static {{message.user.avatar.url}} %}" />

Is there a way to do so where I can find the equivalent working command of the above code?


Solution

  • Try using with

    {% with avatar_url=message.user.avatar.url %}
    <img src="{% static avatar_url %}" />
    {% endwith %}