are anyway to run django project from another python program without useing subprocess or os.system.
im trying to use :
os.system("python manage.py runserver")
and :
subprocess.call("python", "manage.py", "runserver")
but i want to run it from kivy in android and android don't have python builtin
django local server is using as serverside of webwiew.
i find runpy module but it can't run django.
how can i do this ?
edit 1 :
i do it like that Tomasz Jakub Rup say but not work and give below error :
Python 3.5.1 (default, Mar 3 2016, 09:29:07)
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import django
>>> os.environ['DJANGO_SETTINGS_MODULE'] = 'sample.settings'
>>> if hasattr(django, 'setup'):
... django.setup()
...
>>> from django.core.management import call_command
>>> call_command('runserver')
/usr/bin/python: can't find '__main__' module in ''
First You must init django
:
import os
import django
os.environ['DJANGO_SETTINGS_MODULE'] = 'testapp.settings'
if hasattr(django, 'setup'):
django.setup()
from django.core.management import call_command
And run command:
call_command('runserver')
Built in development server of django is fine initially but down the line you might want to use uwsgi or gunicorn to serve your application. They are efficient and can also be made to run on startup in the background rather than launching the shell and you having to run the command manually. You can check more about it here.
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.