<!DOCTYPE html>
{% load staticfiles %}
<html>
........
<img src="{% static 'images/parralax/spaces.jpg' %}" width = 250px />
<body>
以上代码无法显示我设置的背景图片。我不确定该如何解决这个问题。
以下是我的设置文件。我认为问题出在链接到CSS上没有生效。 提前致谢!
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static')
MEDIA_DIR = os.path.join(BASE_DIR,'media')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [.....
],
},
},
]
STATICFILES_DIRS = [STATIC_DIR, ]
STATIC_URL = '/static/'
MEDIA_ROOT = MEDIA_DIR #where to look for files
MEDIA_URL = '/media/' #where to serve files from on url
WSGI_APPLICATION = 'Space.wsgi.application'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
.....
.....
urls.py
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^Spaces/', include('Spaces.urls')),
#Django Admin
path('admin/', admin.site.urls),
#User Management
url(r'^accounts/', include('allauth.urls')),
path(r'^users/', include('users.urls')),
path(r'^users/', include('django.contrib.auth.urls')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_DIR)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_DIR)
请帮忙 :)
干杯!
{% static 'images/parallax/home/9.jpg' %}
会生成什么URL?打开此URL时会得到哪种响应? - Ivan Starostincollectstatic
吗? - Ivan Starostinstatic
函数和STATIC_URL='/static/'
的值,给定的配置将导致127.0.0.1:8000/static/images/parallax/home/9.jpg
。我猜想您没有运行collectstatic
并且正在尝试访问位于Spaces
应用程序子文件夹内的图像。这正确吗? - Ivan StarostinDEBUG = True
还是DEBUG = False
? - ivissani