我试图使用以下代码链接到正确的图像的基础上的评级。但是,服务器将其解释为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"/>
我不知道我在哪里跑错了。你知道吗
问题是变量不是在
{% static 'url' %}
的url参数内插的,所以{{feedback.reception_courtesy}}
是按字面意思理解的。你知道吗这样做:
这很好,因为变量现在在
{% static ... %}
之外,并且{% static 'one/two/three' %}
等价于{% static 'one/two' %}/three
相关问题 更多 >
编程相关推荐