Answer the question
In order to leave comments, you need to log in
How to insert variable into file path in Django template?
Dear Django pros, my lack of experience leads me to ask for help with the following question: I
have a project that has a 'countries' application in which each user enters certain data. The PYGAL module, depending on the entered data, builds an image that is loaded in the template as:
{% load static %}
<img src="{% static 'countries/World.svg' %}" >
<img src="{% static 'countries/World.svg' %}" >
Answer the question
In order to leave comments, you need to log in
The static tag accepts a string or a variable.
If the variable is not in the context:
{% with var1='user/123.svg' %}
<img src="{% static var1 %}">
{% endwith %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question