Builds a barebones Django APP in seconds.
This script automates the setup and configuration of a Django project and app, including the creation of a virtual environment, installation of required packages, and modification of Django's settings.
-
Import Modules:
- Imports necessary Python modules:
os,subprocess,time, and a customvalidate_Namefunction from thevalidationmodule.
- Imports necessary Python modules:
-
Project and App Naming:
- Prompts the user to input a valid Django project name, Django app name, and app location.
- Uses the
validate_Namefunction to ensure the provided names are valid.
-
Path Setup:
- Constructs paths for the Django project's
settings.py,manage.py, project directory, and.envfile based on user input.
- Constructs paths for the Django project's
-
Execution of Commands:
- Runs a series of PowerShell commands to:
- Create the project directory.
- Set up a Python virtual environment.
- Install Django and
python-dotenv. - Create a new Django project and app.
- Set up basic project structure including directories for templates and static files.
- Generate a
.envfile for environment variables.
- Runs a series of PowerShell commands to:
-
Write to
.envFile:- Writes the
api_keyto the.envfile.
- Writes the
-
Modify
settings.py:- Opens the
settings.pyfile and modifies it to:- Import
osandload_dotenv. - Load the
SECRET_KEYfrom the.envfile. - Add the app name to the
INSTALLED_APPSlist. - Set the
STATICFILES_DIRSto include the static directory. - Set the
DIRSin theTEMPLATESsetting to include the templates directory.
- Import
- Opens the
-
Create
runserver.ps1:- Generates a PowerShell script
runserver.ps1that:- Activates the virtual environment.
- Runs the Django development server.
- Generates a PowerShell script
-
Run the Django Server:
- Executes the
runserver.ps1script to start the Django development server. - The script waits for 5 seconds before terminating the server.
- Executes the
This script streamlines the setup process for a Django project by automating the creation and configuration of necessary files and directories. It also sets up a basic development environment with a PowerShell script to run the Django server. Feel free to make changes and if you have recommendations please let me know.