问题
This is my 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',
)
My structure is:
manage.py
myproject
-- __init__.py
-- settings.py
-- urls.py
-- wsgi.py
-- static
----- css
----- img
-------- logo.png
----- scripts
I use the static tag in my html file like this: <img src="{{ STATIC_URL }}img/logo.png">
But, it is:
[Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (logo.png, line 0)
I really can't understand this issue on Django 1.6.2 version.
Could someone help me to solve this issue?
Thanks in advance!
回答1:
You need to make sure that the django.contrib.staticfiles
app is listed in INSTALLED_APPS
:
INSTALLED_APPS = (
...
'django.contrib.staticfiles'
...
)
Lastly, you need to make sure that DEBUG
is set to True
in settings.py
.
EDIT:
Try removing 'django.contrib.staticfiles.finders.DefaultStorageFinder'
from STATICFILES_FINDERS
. Then run $ python manage.py findstatic img/logo.png
来源:https://stackoverflow.com/questions/22339166/staticfiles-on-django-1-6-2