Django 1.6.2上的STATICFILES [英] STATICFILES on Django 1.6.2
问题描述
这是我的 settings.py
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
我的结构是:
manage.py
myproject
-- __init__.py
-- settings.py
-- urls.py
-- wsgi.py
-- static
----- css
----- img
-------- logo.png
----- scripts
我在html文件中使用静态标记,如下所示:< img src ="{{STATIC_URL}} img/logo.png">
I use the static tag in my html file like this: <img src="{{ STATIC_URL }}img/logo.png">
但是,它是:
[Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (logo.png, line 0)
我真的无法理解Django 1.6.2版本上的这个问题.
I really can't understand this issue on Django 1.6.2 version.
有人可以帮我解决这个问题吗?
Could someone help me to solve this issue?
提前谢谢!
推荐答案
您需要确保 django.contrib.staticfiles
应用在 INSTALLED_APPS
中列出:
You need to make sure that the django.contrib.staticfiles
app is listed in INSTALLED_APPS
:
INSTALLED_APPS = (
...
'django.contrib.staticfiles'
...
)
最后,您需要确保在 settings.py
中将 DEBUG
设置为 True
.
Lastly, you need to make sure that DEBUG
is set to True
in settings.py
.
尝试从 STATICFILES_FINDERS
中删除'django.contrib.staticfiles.finders.DefaultStorageFinder'
.然后运行 $ python manage.py findstatic img/logo.png
Try removing 'django.contrib.staticfiles.finders.DefaultStorageFinder'
from STATICFILES_FINDERS
. Then run $ python manage.py findstatic img/logo.png
这篇关于Django 1.6.2上的STATICFILES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!