Django 正在应用背景颜色,但没有应用来自 style.css 的背景图像

Django is applying background color , but not apllying background image from style.css

我 运行 我的 django 项目与 uwsgi。 它读取 statics/css 中的 style.css 文件。 style.css 有两个区域 它适用于第一个区域,但不适用于页面的第二个区域。

1) #skin-blur-violate {
    background: #581528;
}

2) #skin-blur-violate {
    background-image: url(../img/body/violate.jpg);
}

下面是设置中的静态配置。

STATIC_URL = '/home/proj1/static/'

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

STATICFILES_DIRS = (
    '/home/proj1/staticorj/static/',
)

在您的项目 urls.py 中,添加以下代码:

from django.conf import settings
from django.conf.urls.static import static    



if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

并且在您的 settings.py 中仅保留有关 静态文件的代码 并排除您之前拥有的代码:

STATIC_URL = '/static/'    
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

而且,您的 static 文件夹树 应该是这样的:

App
├── static
       ├── app
            └── images
            └── style.css

看看这是否有效。