Python script to create a django project

Python -- Posted on Feb. 13, 2019

Python script to create a django project

              
                import os
import argparse


if __name__ == "__main__":
    ap = argparse.ArgumentParser()
    ap.add_argument("-n", "--name", required=True,
                    help="name of the project")
    args = vars(ap.parse_args())
    name = args["name"]
    path = os.getcwd()
    directory = "{}/sites/{}".format(path, name)
    if not os.path.exists(directory):
        os.mkdir(directory)
    os.chdir(directory)
    if not os.path.exists('public'):
        os.mkdir('public')
    os.system("""python3 -m venv env &&
              . {0}/env/bin/activate &&
              pip install django django-debug-toolbar django-extensions &&
              pip freeze > requirements.txt &&
              django-admin startproject {1} &&
              cd {1} &&
              mkdir static &&
              mkdir templates &&
              cd templates &&
              touch base.html &&
              touch index.html""".format(directory, name))
                  
   
            

Related Posts