如何在 Django 模板中使用三重嵌套引号?
how to use triple nested quotes in django tempates?
我正在尝试使用内联 CSS 并在 Django 模板中加载图像作为背景。
我需要三个引号,但不知道该怎么做。
我该如何修复下面的代码?
<div class="full-background" style="background-image: url("{% static '/img/curved-images/white-curved.jpg' %}")"></div>
它失败了,因为你在双引号中使用了双引号
这是没有 Django 静态文件声明的样子
<div class="full-background" style="background-image: url('path/to/file')"></div>
注意 url 路径周围的单引号
如果要使用Django静态文件,只需在静态声明的内外使用单引号
<div
class="full-background"
style="background-image: url('{% static '/img/curved-images/white-curved.jpg' %}')"
></div>
Django 在查找静态文件时不会看到外部单引号。
我正在尝试使用内联 CSS 并在 Django 模板中加载图像作为背景。 我需要三个引号,但不知道该怎么做。 我该如何修复下面的代码?
<div class="full-background" style="background-image: url("{% static '/img/curved-images/white-curved.jpg' %}")"></div>
它失败了,因为你在双引号中使用了双引号
这是没有 Django 静态文件声明的样子
<div class="full-background" style="background-image: url('path/to/file')"></div>
注意 url 路径周围的单引号
如果要使用Django静态文件,只需在静态声明的内外使用单引号
<div
class="full-background"
style="background-image: url('{% static '/img/curved-images/white-curved.jpg' %}')"
></div>
Django 在查找静态文件时不会看到外部单引号。