2017-04-01 70 views
0

出于某种原因,静态文件,这是由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应该这样做的情况。

回答

0

似乎这不是一次性实例。这发生在django-bowerfinders.py无法找到提供的BOWER_COMPONENTS_ROOT变量中的bower_componentscomponents目录中的任何一个时 - 这就是它所寻找的。

这是无法做到这一点,因为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