0

让我知道这个问题是否足够明显,并且还有这个问题的重复项,我事先无法搜索。

我正在尝试pip install requirements/dev.txt从 Django 管理命令运行。pip ...我有一个逻辑,如果缓存没有改变,不要尝试运行脚本。我想弄清楚如何从 DMC 运行这个命令?

用法:

python manage.py install_prepreqs
Cache is unchanged, skipping.... 

install_prepreqs.py

# I want to run `pip install requirements/dev.txt` with some additional logic. 
4

1 回答 1

0

从 Django 内部运行可能不是一个好主意pip,但是如果您愿意,可以将自己淘汰:djangos custom-management-commands and pythons subprocessmodule

另请参阅有关 subprocess 模块的这篇文章。

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 ...
于 2018-04-18T14:47:33.933 回答