Reputation: 3
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:
Thanks.
Upvotes: 0
Views: 1193
Reputation: 4404
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:
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 %}"
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.
Upvotes: 3