如何以编程方式启动Django [英] How to start Django up programatically
本文介绍了如何以编程方式启动Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
myapp
)和一个Python脚本(让我们说, myscript.py
)都在同一个目录下。如何从脚本启动(并停止)Django应用程序?是否有对象或功能?或者我应该使用子进程
技巧?解决方案
使用 django.core.management.call_command
。
例如:
from django.core import management
management.call_command('runserver')
Suppose I have a Django app (for example, myapp
) and a Python script (let us say, myscript.py
) both in the same directory. How could I start (and stop) the Django app from the script? Is there an object or function for this? Or should I use the subprocess
trick?
解决方案
Use django.core.management.call_command
.
For example:
from django.core import management
management.call_command('runserver')
这篇关于如何以编程方式启动Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文