django - 如何使用命令 python manage.py startapp xxx 生成额外的文件?
问题描述
“python manage.py createapp xxx”命令有一些方法可以生成一些额外的文件,例如,、、xxx.urls
等。statics.dir
template.dir
我希望能够避免必须生成以后可能需要的文件和目录的工作。例如文件;app.urls
, statics.dir
, 等
解决方案
您可以创建自己的 Django 命令。例子:
python manage.py execute_my_command
您的文件夹的结构应该相似。该项目将被称为测试,结构如下:
test
management
commands
__init__.py
execute_python.py
__init__.py
在我们的项目测试中是文件夹管理,在这些命令中和命令中是我们的 python 文件,该文件具有要执行的命令的名称。在 execute_python 内部是命令代码所在的位置:
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = "Ejecuta archivo python archivo_a_ejecutar.py"
def handle(self, *args, **options):
self.stdout.write('Ejecutando comando')
os.system("python archivo_a_ejecutar.py")
推荐阅读
- r - 如何编写一个函数来给出 R 中输入向量数字的发音?
- python - Pytorch TypeError:只有单个元素的整数张量可以转换为索引
- android - 应用启动时 Android ContentResolver.getType 未准备好
- html - CSS - 防止具有未知高度的相对 div 与下面的 div 重叠
- r - 如何每第n列交换一次并格式化R中的内容?
- r - 在 R 中创建具有指定滞后和差异的 ARIMA 模型
- android - Gradle 项目同步在创建后立即失败
- laravel - Laravel,验证时无法将旧值设置为引导 datetimepicker
- javascript - 在对象创建期间使用异步操作时 Vue3 反应性丢失
- eclipse - 为什么我在 osgi 控制台中看不到任何帮助?