Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start Django up programmatically

Tags:

python

django

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?

like image 873
brandizzi Avatar asked May 23 '26 09:05

brandizzi


1 Answers

Use django.core.management.call_command.

For example:

from django.core import management
management.call_command('runserver')
like image 167
David Wolever Avatar answered May 25 '26 22:05

David Wolever