Django服务器静态文件

2024-09-28 05:28:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用以下代码链接到正确的图像的基础上的评级。但是,服务器将其解释为http://127.0.0.1:8000/static/images/rating-%7B%7Bfeedback.reception_courtesy%7D%7D.gif,而不是http://127.0.0.1:8000/static/images/rating-1.gif

<img src="{% static 'images/rating-{{feedback.reception_courtesy}}.gif' %}" alt="My image"/>

我不知道我在哪里跑错了。你知道吗


Tags: 代码图像src服务器httpimg链接static
1条回答
网友
1楼 · 发布于 2024-09-28 05:28:21

问题是变量不是在{% static 'url' %}的url参数内插的,所以{{feedback.reception_courtesy}}是按字面意思理解的。你知道吗

这样做:

<img src="{% static 'images' %}/rating-{{feedback.reception_courtesy}}.gif" alt="My image"/>

这很好,因为变量现在在{% static ... %}之外,并且{% static 'one/two/three' %}等价于{% static 'one/two' %}/three

相关问题 更多 >

    热门问题