【发布时间】:2016-08-03 10:49:04
【问题描述】:
我检查了一个链接,了解如何将图像设置为 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。
我该怎么办?
【问题讨论】:
-
试试
{% static "img.jpg" %} -
试过了...还是一样的结果..
标签: django django-media django-static