user8380069
user8380069

Reputation:

Django template static dynamically

In normal way using static files in Django template we can use:

<img src="{% static 'img/sim/simcard1.png' %}">

My question and ask about help is, how to generate ID with simcardID.png dynamically -depend of variables in view.

<img src="{% static 'img/sim/simcard{{ simid }}.png' %}">

give:

<img src="/static/img/sim/simcard%7B%7B%20simid%20%7D%7D.png">

Anybody help?

Upvotes: 1

Views: 372

Answers (2)

This is an old topic but if anyone reads it, you can do that with with :

{% with 'img/sim/simcard'|add:simid|add:'.png' as img_static %}
    <img src="{% static img_static %}">
{% endwith %}

Upvotes: 1

Ken Mueller
Ken Mueller

Reputation: 4173

<img src="{% static 'img/sim/simcard{{ simid }}.png' %}">

Should be replaced with:

<img src="/static/img/sim/simcard{{ simid }}.png">

Upvotes: 1

Related Questions