Django不提供静态文件
发布于 2021-01-29 14:56:15
我正在使用Django==1.5.5
,我的django应用的结构如下
--project/
----project/
------settings.py
------urls.py
----app1/
------models.py
------views.py
----staticfiles/
------style.css
----static/
------admin/
--------js/
--------css/
------style.css
----templates/
------header.html
------post.html
------footer.html
----manage.py
的/project/settings.py
是
import os
DEBUG = False
TEMPLATE_DEBUG = DEBUG
PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..')
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
MEDIA_ROOT = ''
MEDIA_URL = ''
SITE_ROOT = PROJECT_ROOT
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(SITE_ROOT, 'staticfiles'),
)
TEMPLATE_DIRS = (
os.path.join(SITE_ROOT, 'templates'),
)
在header.html
我尝试使用它为:
<head>
<title>My Site</title>
{% load static from staticfiles %}
<link rel="stylesheet" href="{% static 'style.css' %}">
</head>
但是它没有加载mysite.com/static/style.css
并给出错误404
我跑去python manage.py collectstatic
收集所有静态文件。
为什么要加载CSS文件?是否缺少任何配置?
请提出建议。
关注者
0
被浏览
98