简体   繁体   English

无法添加Django-Assets / Webassets目录以查找assets.py文件

[英]Trouble adding Django-Assets / Webassets directory to look for assets.py files

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. 正在寻找一个用于Django的Python软件包来管理资产,使用Sass编译CSS以及缓存清除,因此建议使用Django-Assets / Webassets。 Having trouble getting it setup though with my directory structure. 使用我的目录结构无法进行设置。

By default it looks for assets.py in each installed app. 默认情况下, assets.py在每个已安装的应用程序中查找assets.py 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 . 我想对其进行设置,使其与settings.py位于同一目录中,并将来自每个应用程序目录的特定于应用程序的资产编译到/static/js/static/css

I have django_assets in INSTALLED_APPS . 我在INSTALLED_APPSdjango_assets According to the docs it looks like I needed to add this to settings.py : 根据文档 ,看来我需要将其添加到settings.py

ASSETS_MODULES = [
   'project_dir',
]

Or: 要么:

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

Or: 要么:

ASSETS_MODULES = [
   PROJECT_ROOT
]

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. 无论如何,它只会返回未No asset bundles were found. If you are defining assets directly within your template, you want to use the --parse-templates option. No asset bundles were found. If you are defining assets directly within your template, you want to use the --parse-templates option.

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 . 即使将assets.py移至应用程序目录之一,它也会在BASE_DIR/scripts查找,这是我保留manage.py Again, changing ASSETS_ROOT doesn't really same to be doing anything. 同样,更改ASSETS_ROOT与执行任何操作并不完全相同。

~/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

Couple of quick notes, for ASSETS_MODULES , the key word is additional: 快速笔记,对于ASSETS_MODULES ,关键字是附加的:

django-assets will automatically look for assets.py files in each application, where you can register your bundles. django-assets将在每个应用程序中自动查找assets.py文件,您可以在其中注册捆绑包。 If you want additional modules to be loaded, you can define this setting. 如果要加载其他模块,则可以定义此设置。 It expects a list of importable modules: 它需要可导入模块的列表:

ie, we only use ASSETS_MODULES if we have assets.py files outside of any application. 也就是说,如果我们在任何应用程序之外都拥有assets.py文件,则仅使用ASSETS_MODULES In your case, we will only specify this if project_dir is not an INSTALLED_APP . 对于您而言,仅当project_dir不是INSTALLED_APP ,我们才指定此名称。

Second, when using ASSETS_MODULES , you specify a dotted module path, not a directory. 其次,在使用ASSETS_MODULES ,您指定的是虚线模块路径,而不是目录。 In your case, this would be project_dir.assets only if project_dir is not already part of INSTALLED_APPS . 在您的情况下,仅当project_dir还不是INSTALLED_APPS一部分时,这才是project_dir.assets

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

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