0

How to concat a string and a jinja expression inside jinja statement?

{% for pic in pictures %}
    {% if pic.name == line.name %}
        <img class="card-img-top" src="{% static 'orders/img/'pic.picture %}" >
    {% endif %}
{% endfor %}

In this tag with Jinja, the pic.picture is a jinja express but how to concat with 'orders/img/'?

Image: 1

Thanks.

Pedram Parsian
  • 3,750
  • 3
  • 19
  • 34
JimJim
  • 3
  • 3

1 Answers1

3

Default Django Template Language looks like Jinja but is not one - it has it's own filters and does not support all Jinja tags/filters.

Available options with Django built-in filters:

  • join strings with add filter (although it is not recommended as will try to convert to integer, more about it here, but if part is clearly a string...):
src="{% static 'orders/img/'|add:pic.picture %}"
  • no join, resolve base static path and append file name after:
src="{% static 'orders/img/' %}{{ pic.picture }}"
{% get_static_prefix as STATIC_PREFIX %}
src="{{ STATIC_PREFIX }}orders/img/{{ pic.picture }}"

Jinja2 can be configured as django template backend.

Oleg Russkin
  • 4,234
  • 1
  • 8
  • 20