我有下一个配置:
urls.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)
settings.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
我的静态文件配置有什么问题?