在Django中加载具有变量名的静态文件 [英] load static file with variable name in django
本文介绍了在Django中加载具有变量名的静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试加载以下静态文件
I'm trying to do load the following static file
<a href="{%static 'static/images/'{{ image.title }}'.png' %}">img file</a>
其中 image
处于for循环中图像
来自数据库。
where image
is in a for loop of images
derived from a database.
但是我只是遇到一个错误无法解析余数:'{{from'static / matrices /'{{'
But I simply got an error Could not parse the remainder: '{{' from ''static/matrices/'{{'
我该怎么做才能解决此问题?我不能使用相对路径,因为同样的html模板也将被小节使用。
What should I do to fix this? I can't use relative paths because this will be used by subsections as well, with the same html template.
推荐答案
太多
Just
<a href="{% static 'images/{{ image.title }}.png' %}">img file</a>
,您不必在链接中调用静态变量,因为您已经加载了静态变量
and you don't have to call the static in the link because you already load the static
这篇关于在Django中加载具有变量名的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文