0

我有下一个配置:

网址.py

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^manager/', include('manager.urls')),

    #Static pages
    url(r'^index', TemplateView.as_view(template_name='index.html'), name='index'),
    url(r'^', TemplateView.as_view(template_name='index.html'), name='index'),
    url(r'^contact', TemplateView.as_view(template_name='contact.html'), name='contact'),
    url(r'^services', TemplateView.as_view(template_name='services.html'), name='services'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

设置.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'pf.app.pfs',
]

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "assets"),
    #'/var/www/static/',
]

我执行了命令:

python manage.py collectstatic

并生成了文件,我还添加了一个带有单个规则的 css 文件,但再次执行了该命令。

但是,在将其添加到我的 html 文件中的瞬间

    <head>
        {% load static %}
<link rel="stylesheet" href="{% static 'css/style.css' %}" />
</head>

在我得到的 html 中:

<link rel="stylesheet" href="/static/css/style.css">

在终端:

“GET /static/css/style.css HTTP/1.1”404 1766

我的静态文件配置有什么问题?

在此处输入图像描述

4

0 回答 0