Django 1.7 - 提供静态文件 [英] Django 1.7 - Serving static files
问题描述
我正在关注官方文档,以便提供静态文件,但是我在开发控制台中收到错误404。我使用'django.contrib.staticfiles',所以应该自动提供静态文件。这是我的设置:
I'm following the official documentation in order to serve static files but I'm recieving error 404 in the development console. I'm using 'django.contrib.staticfiles', so static files should be automatically served. This is my setup:
设置:
STATIC_ROOT = ''
STATIC_URL = '/static/'
模板标题:
{% load staticfiles %}
<link rel="stylesheet" href="{% static "css/app.css" %}">
目录树:
django_project
\apps
\static
\css
app.css
\templates
index.html
我可以在firefox控制台看到我的文件的路径是正确的:
I can see in firefox console that the path to my file is correct:
所以问题一定是Django不提供静态文件。我找不到我失踪的东西任何建议都是比较受欢迎的。
So the problem must be that Django is not serving static files. I can't find what I'm missing. Any advice is more than welcome.
推荐答案
解决方案:
我错过了这一行在我的settings.py
SOLUTION: I was missing this line in my settings.py
STATICFILES_DIRS = (os.path.join(os.path.dirname(__file__),'static'),)
它看起来是强制性的,与TEMPLATE_DIRS相同。
It looks it's mandatory, same as TEMPLATE_DIRS.
这篇关于Django 1.7 - 提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!