使用 django_extensions
安装
pip install django_extensions
在 INSTALLED_APPS 中引入
INSTALLED_APPS = [
···
'django_extensions'
···
]
使用
在项目下执行
mkdir scripts
touch scripts/__init__.py
创建脚本
touch scripts/test.py
vi scripts/test.py
def run(): # 入口就是run 类似于main
print('test')
运行
python mange.py runscript test
输出
test