我已经检查了如何将图像设置为背景的链接div
。我尝试了各种方法。但仍然在某个地方出错,需要一些指导......
下面是我的目录结构:
frontend
/frontend (django project)
settings.py
.
.
/webApp (django app)
/templates
/static
img1.jpg
home.html
在我的home.html
我有以下行,
{% load static %}
<div style="background-image: url({% static "/img1.jpg"%}); height: 650px; width: 1920px;">
在settings.py
我有,
STATIC_URL = '/static/'
但是显示页面时没有出现图像。我收到以下错误。
"GET /static/img1.jpg HTTP/1.1" 404 1803
我的目录结构不同,之前已经搜索了几个问题以满足我的需要。我仍然对 url 和为背景图像分配 url 感到困惑。我也希望它作为一个url
而不是href
设置background-image
。我该怎么做?