Summary:
How do I reference static files in the handlebars part of a django template? I can use rudders if I use verbatim tags, but then I cannot use django static tag.
More details
When converting the application to Django, I came across a part that uses handelbars.js to render ajax-call-results. Via, among others, Handlebars.js in Django templates "I learned about the tag {% verbatim %} .
The simple part of the rudders works great with this. But I also have a part where images are dynamically displayed based on a result that looks something like this:
<img src="path/{{ result }}.png">
Now that it works fine, if I set the path manually, I believe in Django, it is good practice to refer to your static files as follows:
<img src="{% static 'path/file.png' %}">
Just getting static_url constant static_url not recommended, see, for example, this blog
Therefore, if someone does not have a real convincing reason to correct this otherwise, I believe that it is better to use the {% static %} method.
A naive solution would be to combine the 2 methods and literally spray the template with the literal / endverbatim. Besides the fact that it looks ugly, inaudible and seems like a bad idea from the very beginning, it also doesn't work.
{% verbatim %} {% endverbatim %} <img src="{% static 'path{% verbatim %}{{ result }}{% endverbatim %}' %}"> {% verbatim %} {% endverbatim %}
It ends in tears, as the result
TemplateSyntaxError at /
Failed to parse the remainder: '' path {% 'from' 'path {%'
Perhaps you can create the correct static server-side URL and do this. But the backend does not need to know which image we want to display in the template.
Only a solution can consist in an additional call to the backend with a "relative" string (for example, path/result.png ) on the backend and requesting the correct static link? This is not so difficult, but requires an additional call, which should not be.
So, how to reference these static files correctly?