How to passing queryset inside static url in django template?

Tags: , ,

So, I have image in static folder, with the name of image same with username field that I have created. I want to show the photo for every posting based on the post that made by that user. I just thinking to pass the queryset inside static url like this:

{% for post in data %}
<img src="{% static 'project/image/{{ post.username }}.jpg' %}" alt="Profile" id="profile_image">
{% endfor %}

But my image don’t want to show up (error), and the terminal looks like this:

[27/Feb/2021 15:43:14] "GET /static/project/image/%7B%7B%20post.username%20%7D%7D.jpg HTTP/1.1" 404 1758

Is there any way to do this?


If you want to use the curly brackets, then you need to hard code the whole path of the image.

static/project/image/{{ post.username }}.jpg

Source: stackoverflow