如何以编程方式启动Django [英] How to start Django up programmatically

查看:56
本文介绍了如何以编程方式启动Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在同一个目录中有一个Django应用(例如 myapp )和一个Python脚本(让我们说 myscript.py ).如何从脚本启动(和停止)Django应用程序?为此有一个对象或功能吗?还是应该使用 subprocess 技巧?

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?

推荐答案

使用例如:

from django.core import management
management.call_command('runserver')

这篇关于如何以编程方式启动Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆