Django的亭子:静态文件由BowerFinder加载未发现
问题描述:
出于某种原因,静态文件,这是由djangobower.finders.BowerFinder
加载不加载(得到404服务器未找到)Django的亭子:静态文件由BowerFinder加载未发现
设置。 PY
STATIC_ROOT = "/root/Desktop/django-DefectDojo/static/"
STATIC_URL = '/static/'
STATICFILES_DIRS =()
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'djangobower.finders.BowerFinder',
)
BOWER_COMPONENTS_ROOT = '/root/Desktop/django-DefectDojo/components/'
BOWER_INSTALLED_APPS = (
'jquery-ui',
)
INSTALLED_APPS = (
'djangobower',
)
模板
<script src="{% static "jquery-ui/jquery-ui.min.js" %}"></script>
项目结构
-project root
-static
-components
-vendor
-assets
-bower-components
-jquery-ui
-jquery-ui.min.js
我做了./manage.py bower install
后跟一个./manage.py collectstatic
现在,上运行的服务器,我得到一个没有找到。
但是,当我制作STATICFILES_DIRS = ('/root/Desktop/django-DefectDojo/components/vendor/assets/bower_components/',)
时,则会加载静态文件。 但这不应该是BowerFinder
应该这样做的情况。
答
似乎这不是一次性实例。这发生在django-bower
的finders.py
无法找到提供的BOWER_COMPONENTS_ROOT
变量中的bower_components
或components
目录中的任何一个时 - 这就是它所寻找的。
这是无法做到这一点,因为bower install
现在创建bower_components
目录如下:
-projectroot
-components
-vendors
-assets
-bower_components
-
-
对抗:
-projectroot
-components
-bower_components
-
-
最简单的方法来解决,这是设置BOWER_COMPONENTS_ROOT = os.path.join(PROJECT_ROOT, 'components\vendors\assets')
而不是只做BOWER_COMPONENTS_ROOT = os.path.join(PROJECT_ROOT, 'components')
从django-bower
的回购: https://github.com/nvbn/django-bower/issues/20