在django中加载带有变量名的静态文件 [英] load static file with variable name in django

查看:27
本文介绍了在django中加载带有变量名的静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载以下静态文件

I'm trying to do load the following static file

 <a href="{%static 'static/images/'{{ image.title }}'.png' %}">img file</a> 

其中 image 位于从数据库派生的 images 的 for 循环中.

where image is in a for loop of images derived from a database.

但我只是得到一个错误无法解析余数:'{{' 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.

推荐答案

引用太多!

<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆