Django 1.6.2 的 STATICFILES
这是我的 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">
但是,它显示的是:
[Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (logo.png, line 0)
我真的无法理解在 Django 1.6.2 版本中出现的这个问题。
有人能帮我解决这个问题吗?
提前谢谢大家!
1 个回答
0
你需要确保 django.contrib.staticfiles
这个应用在 INSTALLED_APPS
列表中。
INSTALLED_APPS = (
...
'django.contrib.staticfiles'
...
)
最后,你还需要确保在 settings.py
文件中,DEBUG
的值设置为 True
。
编辑:
试着把 'django.contrib.staticfiles.finders.DefaultStorageFinder'
从 STATICFILES_FINDERS
中移除。然后运行 $ python manage.py findstatic img/logo.png
。