如何编写一个脚本,为 django 执行 collectstatic

Pau*_*ner 13 command-line bash scripts expect

我想为我的 django 应用程序做一个自动 collectstatic 脚本。我尝试了各种方法,但没有奏效。我的最后一次尝试是在普通脚本中调用一个期望脚本:

收集静态.sh:

python manage.py collectstatic --settings=app.settings_mark &&
./testscript.sh
Run Code Online (Sandbox Code Playgroud)

测试脚本.sh:

#!/usr/bin/expect -f
spawn testscript.sh
expect "Type 'yes' to continue, or 'no' to cancel:"
send "yes"
Run Code Online (Sandbox Code Playgroud)

但是,该行./testscript.sh永远不会执行,因为collectstatic之前的命令正在等待输入。我怎么能跳过那个?我也试过省略,&&但没有用。

提前致谢 !

小智 15

你可以试试

python manage.py collectstatic --noinput
Run Code Online (Sandbox Code Playgroud)


mur*_*uru 6

为什么不直接发送yes到输入manage.py

python manage.py collectstatic --settings=app.settings_mark <<<yes &&
./testscript.sh
Run Code Online (Sandbox Code Playgroud)

或者:

echo yes | python manage.py collectstatic --settings=app.settings_mark &&
./testscript.sh
Run Code Online (Sandbox Code Playgroud)

  • 你可以用 noinput 参数完成同样的事情: manage.py collectstatic --noinput http://stackoverflow.com/questions/8705305/automated-django-receive-hook-on-server-respond-to-collectstatic-with-是的 (8认同)