简体   繁体   English

Django 1.6.2上的STATICFILES

[英]STATICFILES on Django 1.6.2

This is my settings.py 这是我的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"> 我在html文件中使用静态标签,如下所示: <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. 我真的无法理解Django 1.6.2版本上的这个问题。

Could someone help me to solve this issue? 有人可以帮我解决这个问题吗?

Thanks in advance! 提前致谢!

You need to make sure that the django.contrib.staticfiles app is listed in INSTALLED_APPS : 您需要确保django.contrib.staticfiles应用程序已在INSTALLED_APPS列出:

INSTALLED_APPS = (
    ...
    'django.contrib.staticfiles'
    ...
)

Lastly, you need to make sure that DEBUG is set to True in settings.py . 最后,您需要确保在settings.py中将DEBUG设置为True

EDIT: 编辑:

Try removing 'django.contrib.staticfiles.finders.DefaultStorageFinder' from STATICFILES_FINDERS . 尝试从STATICFILES_FINDERS删除'django.contrib.staticfiles.finders.DefaultStorageFinder' Then run $ python manage.py findstatic img/logo.png 然后运行$ python manage.py findstatic img/logo.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM