Difference between revisions of "Django management program"
(Created page with "Running and using django in the college environment can be difficult. So i have written this program to perform the key django functions: <syntaxhighlight lang=python> import...") |
(No difference)
|
Revision as of 11:17, 1 May 2019
Running and using django in the college environment can be difficult. So i have written this program to perform the key django functions:
import os,sys
def djangocommand(option):
DJANGO_PATH = ""
for p in sys.path:
if p.find('Scripts') != -1:
DJANGO_PATH = p[0:p.find('Scripts')]+"Scripts\python "+p[0:p.find('Scripts')]+"Scripts\django-admin.py"
os.system(DJANGO_PATH + " "+option)
def managecommand(option):
for p in sys.path:
if p.find('Scripts') != -1:
MANAGE_PATH = p[0:p.find('Scripts')]+"Scripts\python "
MANAGE_PATH +=os.path.dirname(os.path.realpath(__file__))+ "\manage.py"+" "+option
print(MANAGE_PATH)
os.system(MANAGE_PATH)
print('Do you want to use:')
print('1: Django-admin')
print('2: Manage')
manoption=input("Please Select 1 or 2:")
if manoption=='1':
print('What django-admin command do you want to run:')
print('1: StartProject')
print('2: StartApp')
option = input("Please Select 1 or 2:")
if option=='1':
name = input("Please enter a project name:")
djangocommand("startproject "+name+" .")
elif option=='2':
name = input("Please enter a app name:")
djangocommand("startapp "+name)
else:
print("invalid option, please re-run")
elif manoption=='2':
print('What django-admin command do you want to run:')
print('1: Runserver')
print('2: MakeMigrations')
print('3: Migrate')
option = input("Please Select 1, 2 or 3:")
if option=='1':
managecommand("runserver")
elif option=='2':
managecommand("makemigrations")
elif option=='2':
managecommand("migrate")
else:
print("invalid option, please re-run")
else:
print("invalid option, please re-run")