Reputation: 701
In one of my templates I use
{% for key, value in dict.items %}
...
<img src="{% static 'img/{{ key|slugify }}.jpg' %}"/>
...
{% endfor %}
but the output is not the one expected so I guess that one cannot use template filters within a static
tag.
Any suggestions on how to achieve this then?
Edit: the keys of the dict above are strings that corresponds to the filenames of the jpg images.
Upvotes: 0
Views: 679
Reputation: 476
Use get_static_prefix tag:
{% load static %}
{% for key, value in dict.items %}
...
<img src="{% get_static_prefix %}img/{{ key|slugify }}.jpg"/>
...
{% endfor %}
Upvotes: 1