问题
I am trying to use the Django template tags to bring up specific images that correlate with each choice, however it does not seem to work, just return a broken image. Here is my relevant html:
<img class="img-responsive" src="{% static "images/risk_graphics/{{ input.choice }}.jpg" %}"/>
Thanks for any help.
回答1:
Just set a variable on the context containing the path to the file in question. You can reference variables in the static template tag (here named special_image_path):
<img class="img-responsive" src="{% static special_image_path %}"/>
See the second example here in the Django docs
来源:https://stackoverflow.com/questions/32532524/use-django-template-tags-in-img-src