让我知道这个问题是否足够明显,而且这个问题也有重复,我事先未能进行搜索。
我正在尝试从Django管理命令运行pip install requirements/dev.txt
。我有一个逻辑,如果缓存不变,不要尝试运行脚本pip ...
。我想弄清楚如何从DMC运行这个命令?
python manage.py install_prepreqs
Cache is unchanged, skipping....
# I want to run `pip install requirements/dev.txt` with some additional logic.
答案 0 :(得分:0)
从Django内部运行pip
可能不是一个好主意,但是如果你愿意,那就自己敲门:djangos custom-management-commands和pythons subprocess
module
另请参阅this post有关子流程模块的信息。
from django.core.management.base import BaseCommand, CommandError
import subprocess
class Command(BaseCommand):
def handle(self, *args, **options):
# check your precondition logic here
# ... your code goes here ...
if my_condition == True:
subprocess.run(["ls", "-l"])
# ... some more code goes here if you wish ...