[Answer]-Absolute static url in template tags

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

Leave a comment