python - How to reference dynamic file within {% static %} call? -
Here the newgen newzer is starting with my first app ...
I need to reference within my static property folder ([project] / static / picture / ____ .jpg) and I'm using the {% static%} template tag similar to the example in the initial tutorial:
< Pre> {% load staticfiles%} & lt; Img src = "{% static" my_app / image.jpg "%}" & gt;
However, I need to reference the image file that uses a variable which is passed from the view.py file. Of course, this syntax does not work, but I should make it clear what I am trying to do.
& lt; Img src = "{% static" my_app / {{imagevariable}} "%}" & gt;
What is the correct syntax for referencing this variable within a constant template tag? Try
with one
< Code> {% "myapp /" | With: add: imagevariable as file name%} & lt; Img src = "{% static file name%}" & gt; {% Endwith%}
You can also use get_static_prefix:
& lt; Img src = "{% get_static_prefix%} myapp / {{imagevariable}}" & gt;
Comments
Post a Comment