我正在为django-oscar
完成Frobshop示例项目。
关于自定义资产的django-oscar
文档相当简洁,而我报告的manage.py oscar_fork_statics
未解决的错误只是增加了混乱。这是我手动复制文件并编译资源的(失败)尝试。
我在/var/work/django/frobshop/
安装了Frobshop。
我在/var/work/django/oscar/
中为django-oscar
安装了一个虚拟环境,所以发行版的资产目录在该目录中,在lib/python3.8/site-packages/oscar/static/oscar/
中。该目录下的README.rst
文件显示When building your own project, it is not recommended to use these files straight from the package. Rather, you should take a static copy of the ``oscar/static/oscar`` folder and commit it into your project.
看起来很简单,所以我输入:
$ cd /var/work/django
$ mkdir frobshop/frobshop/static/
$ cp -a lib/python3.8/site-packages/oscar/static/oscar/* frobshop/frobshop/static/
下一步,README.rst
说:You can compile the static assets from the root of the project using a make target: make assets
.
$ make assets
make: *** No rule to make target 'assets'. Stop.
嗯,那没有用。是https://github.com/django-oscar/django-oscar/blob/master/Makefile正确的Makefile
,我想知道,它应该位于哪里?
$ wget -O frobshop/static/Makefile
https://raw.githubusercontent.com/django-oscar/django-oscar/master/Makefile
运行make assets
给了我一个错误消息,抱怨缺少package.json
,所以我也从django-oscar
中抓取了它。
$ wget -O frobshop/static/package.json
https://raw.githubusercontent.com/django-oscar/django-oscar/master/package.json
似乎我应该从新的frobshop/frobshop/static/
目录运行make
:
$ (cd frobshop/static/; make assets)
安装了许多文件,然后最终出现了这个消息:
found 3 vulnerabilities (2 moderate, 1 high)
run `npm audit fix` to fix them, or `npm audit` for details
npm run build
> django-oscar@3.0.0 build /var/work/django/frobshopCamille/frobshop/static
> gulp copy && gulp scss
[11:32:39] No gulpfile found
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! django-oscar@3.0.0 build: `gulp copy && gulp scss`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the django-oscar@3.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/mslinn/.npm/_logs/2021-02-19T16_32_39_097Z-debug.log
make: *** [Makefile:29: assets] Error 1
我不知道该怎么处理这个错误。我在django-oscar
中看到一个名为gulpfile.js
的目录。我应该把它复制到什么地方吗?
README.rst
接着说:If you make changes to Oscar's assets in development, you can run ``npm run watch`` to automatically watch and compile changes to them.
$ (cd frobshop/static/; npm run watch)
当然,这只会产生与之前相同的错误消息。
在src/oscar/static_src/oscar/README.rst
中提到的编译资产的说明(使用make assets
,它运行Gulp任务)实际上只适用于开发/打包django-oscar
本身。我们将尽力使文件更清楚。
对于一个基于django-oscar的项目/商店,你只需要运行./manage.py collectstatic
,使用Oscar的静态文件而不需要修改,就像这里提到的:https://django-oscar.readthedocs.io/en/latest/howto/how_to_handle_statics.html#customising-statics
要修改和覆盖Oscar的静态文件,您还需要运行./manage.py oscar_fork_statics
,将Oscar的静态文件复制到您的项目中。该命令目前已损坏,但我们正在修复:https://github.com/django-oscar/django-oscar/pull/3657