django 1.5 – How to use variables inside static tag

You should be able to concatenate strings with the add template filter:

{% with 'assets/flags/'|add:request.LANGUAGE_CODE|add:'.gif' as image_static %}
  {% static image_static %}
{% endwith %}

What you are trying to do doesn’t work with the static template tag because it takes either a string or a variable only:

{% static "myapp/css/base.css" %}
{% static variable_with_path %}
{% static "myapp/css/base.css" as admin_base_css %}
{% static variable_with_path as varname %}

Leave a Comment