Use Django Template Tags in img src [duplicate]

柔情痞子 提交于 2019-12-11 19:41:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!