Building Your First Django App: A Step-by-Step Tutorial

Step 1: Create a folder and install Virtual Environment
Create a folder in your computer( Ex: My Django App) and open that folder in Code Editor like VS code (Right click and choose "Open with VS Code").
Note: Here "venv" is a virtual environment name.
Step 2: Activate the Virtual Environment and install Django in a virtual environment
Activate the virtual environment using the following command
Note: If you cannot activate virtual environment and getting error message like "venv/Scripts/Activate.ps1 : File E:\Django for Production office apps\venv\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170."
Solution: You need to set powershell ExecutionPolicy to Unrestricted using the following command.Just paste the command in Power shell.
Then install the Django using the following command
Step 3: Create a main project and create a separate app
Create a main Django project using the following command
Note: Here "main" is the main project name. You can use the command without the dot "django-admin startproject main". Using the command without dot will create a folder with your main project name and add files with the same name inside the folder.
If you want to create seperate app, use this command:
Note: Here "myapp" is an app name.
Step 4: Connect the app with the main project and connect the separate app URLs to the main project
Open main app settings.py file: main/settings.py
If your app doesn’t have a urls.py, create one:
Then, connect your app’s URLs to your main project’s urls.py:
Step 5: Run the app.
Run the app using the following command
Step 6 (optional): Create another separate app to add a Custom user model (if it's necessary)
Code block icon 1