无法添加Django-Assets/Webassets目录以查找assets.py文件 [英] Trouble adding Django-Assets / Webassets directory to look for assets.py files

查看:38
本文介绍了无法添加Django-Assets/Webassets目录以查找assets.py文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在寻找Python软件包供Django管理资产,使用Sass编译CSS以及缓存清除功能时,建议使用Django-Assets/Webassets.使用我的目录结构无法进行设置.

Was looking for a Python package for Django to manage assets, using Sass to compile CSS, and also cache busting, and Django-Assets / Webassets was recommended. Having trouble getting it setup though with my directory structure.

默认情况下,它会在每个已安装的应用程序中查找 assets.py .我想对其进行设置,使其与 settings.py 位于同一目录,并将来自每个应用程序目录的特定于应用程序的资产编译到/static/js /static/css .

By default it looks for assets.py in each installed app. I want to set it up so that it sits in the same directory as settings.py and compiles app specific assets from each app directory into /static/js and /static/css.

我在 INSTALLED_APPS 中有 django_assets .根据文档,它看起来像我需要将此添加到 settings.py :

I have django_assets in INSTALLED_APPS. According to the docs it looks like I needed to add this to settings.py:

ASSETS_MODULES = [
   'project_dir',
]

或者:

ASSETS_MODULES = [
   os.path.join(BASE_DIR, 'project_dir'),
]

或者:

ASSETS_MODULES = [
   PROJECT_ROOT
]

无论如何,它只会返回未找到资产束.如果要直接在模板中定义资产,则要使用--parse-templates选项.

At any rate, it just returns No asset bundles were found. If you are defining assets directly within your template, you want to use the --parse-templates option.

即使将 assets.py 移至应用程序目录之一,它也会在 BASE_DIR/scripts 中查找,这是我保存 manage.py .同样,更改 ASSETS_ROOT 与做任何事情并不完全相同.

Even moving the assets.py into one of the app directories, it is looking in BASE_DIR/scripts which is where I keep my manage.py. Again, changing ASSETS_ROOT doesn't really same to be doing anything.

~/portal-client

project_dir
    apps
        account
            templates
                account
                    login.html
            forms.py
            urls.py
            views.py
        home
            templates
                home
                    home.html
            urls.py
            views.py
        results
    assets.py
    settings.py
    urls.py
scripts
    manage.py
static
templates
    base.html
    footer.html
    title.html

推荐答案

快速笔记的组合,对于 ASSETS_MODULES ,关键字是附加的:

Couple of quick notes, for ASSETS_MODULES, the key word is additional:

django-assets将在每个应用程序中自动查找 assets.py 文件,您可以在其中注册捆绑包.如果要加载其他模块,则可以定义此设置.它需要可导入模块的列表:

django-assets will automatically look for assets.py files in each application, where you can register your bundles. If you want additional modules to be loaded, you can define this setting. It expects a list of importable modules:

即,如果我们在任何应用程序之外都具有 assets.py 文件,则仅使用 ASSETS_MODULES .对于您而言,仅当 project_dir 不是 INSTALLED_APP 时,我们才指定此名称.

i.e., we only use ASSETS_MODULES if we have assets.py files outside of any application. In your case, we will only specify this if project_dir is not an INSTALLED_APP.

第二,当使用 ASSETS_MODULES 时,您指定的是虚线模块路径,而不是目录.在您的情况下,仅当 project_dir 还不是 INSTALLED_APPS 的一部分时,这才是 project_dir.assets .

Second, when using ASSETS_MODULES, you specify a dotted module path, not a directory. In your case, this would be project_dir.assets only if project_dir is not already part of INSTALLED_APPS.

这篇关于无法添加Django-Assets/Webassets目录以查找assets.py文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆