Python 在django 1.8中提供静态文件
我的Python 在django 1.8中提供静态文件,python,django,django-templates,Python,Django,Django Templates,我的404.html页面没有引用我的finale.css文件。 我的目录结构 musicworld/ musicworld/ __pycache__ __int__.py settings.py urls.py wsgi.py feature/ __pycache__ migrations static/
404.html
页面没有引用我的finale.css
文件。
我的目录结构
musicworld/
musicworld/
__pycache__
__int__.py
settings.py
urls.py
wsgi.py
feature/
__pycache__
migrations
static/
feature/
finale.css
templates/
feature/
about.html
detail.html
404.html
500.html
index.html
template.html
__init__.py
admin.py
models.py
tests
这就是我在index.html
中引用css的地方
<link rel="stylesheet" type="text/css" href="{% static 'feature/finale.css' %}" />
{% extends "index.html" %}
{% load staticfiles %}
{% block 404page %}
<div class="box">
<p class="box-message" data-dead-message="AAAAAHHHHHH!">Oh No! Something went wrong.Punish the developer by clicking here.</p>
</div>
<div class="robot">
<img src="" alt="Robot" />
</div>
{% endblock %}
settings.py中的静态引用
STATIC_URL = '/static/'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
ALLOWED_HOSTS = ['*']
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
index.html
和template.html
都放在同一个文件夹中,并且正确地引用了css。另外,功能中扩展index.html
的所有html
页面也引用了css。但是404.html
和500.html
都没有引用css。您的想法是什么settings.py
中的STATIC\u URL
设置?你运行命令了吗?@tatlarSTATIC\u URL='/STATIC/'
。从未见过那个命令,对django来说是新的。但是如果有必要,其他模板不会引用css文件。它们会吗?在settings.py中显示包含static
的所有行。可能有问题。@AbhiP我已将该部分编辑到代码中。请参见以下问题: