我有这个代码。<div class="g-fullheight--xs g-bg-position--center swiper-slide" style="background:{% static'/img/1920x1080/02.jpg' %}">
但这是行不通的:未设置背景,但网址似乎正常,没有http错误。
如何在样式中添加路径。正确使用Jinja
原始代码是
<div class="g-fullheight--xs g-bg-position--center swiper-slide" style="background: url('img/1920x1080/01.jpg');">
解决了
解
<div class="g-fullheight--xs g-bg-position--center swiper-slide" style="background: url({% static '/img/1920x1080/02.jpg' %})">
最佳答案
原始代码:
style="background: url('img/1920x1080/01.jpg');">
jinja代码:
style="background:{% static'/img/1920x1080/02.jpg' %}
这将导致:
style="background: /my/static/img/1920x1080/02.jpg"
看到这段代码和原始代码之间的区别了吗?
url('')
丢失。关于css - 无法使用CSS将静态文件(图像)设置为背景,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53569579/