【问题标题】:django-bower: Static files to be loaded by BowerFinder not founddjango-bower:找不到 BowerFinder 要加载的静态文件
【发布时间】:2017-04-01 08:58:52
【问题描述】:

由于某种原因,djangobower.finders.BowerFinder 要加载的静态文件没有加载(在服务器中得到 404 Not Found)

settings.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

现在,在运行服务器时,我得到一个 Not Found。

但是,当我制作 STATICFILES_DIRS = ('/root/Desktop/django-DefectDojo/components/vendor/assets/bower_components/',) 时,静态文件会被加载。 但这不应该是这样,因为BowerFinder 应该这样做。

【问题讨论】:

    标签: django bower django-staticfiles static-files


    【解决方案1】:

    似乎这不是一次性的实例。当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's repo 的相关帖子: https://github.com/nvbn/django-bower/issues/20

    【讨论】:

      【解决方案2】:

      Bower 直接在我的 Django 根目录中创建了 bower_components。 因此我只需要在settings.py 中执行此操作:

      BOWER_COMPONENTS_ROOT = BASE_DIR
      

      【讨论】:

      • 鲍泽?你是说鲍尔吗?
      猜你喜欢
      • 1970-01-01
      • 2021-09-04
      • 2017-11-08
      • 1970-01-01
      • 2021-08-27
      • 2014-11-10
      • 2011-08-26
      • 2020-06-22
      • 2021-08-16
      相关资源
      最近更新 更多