1π
β
Is it required for you to return the entire image object instead of just the name of the file? If itβs not, you could try:
β¦ extras.py
@register.filter(name="flag")
def flag(language):
if language == 'fr':
return 'french'
elif language == 'ge':
return 'german'
html
<td class="subtitle-flag">
{% with flag_name=subtitle.language|flag|safe %}
<img src="{% static 'img/flags/'|add:flag_name|add:'.jpg' %}" class="flag" />
{% endwith %}
</td>
Read the docs for more information about the add
filter and with
tag.
π€Aylen
Source:stackexchange.com