Django
Step 1: Create a Virtual Environment
python -m venv venv
What it does: Creates a virtual environment named venv . This is an isolated Python environment
where you can install project-specific dependencies without interfering with the system's Python or other
projects.
Step 2: Activate the Virtual Environment
On Windows:
source venv/Scripts/activate
On Mac/Linux:
source venv/bin/activate
What it does: Activates the virtual environment so that the Python interpreter and libraries from this
environment are used instead of the system-wide versions.
Step 3: Install Django
pip install django
What it does: Installs Django in your virtual environment. This ensures that Django is accessible within
your project.
Step 4: Create a New Django Project
django-admin startproject projectname
What it does: Creates a new Django project named prem . This generates the following structure:
projectname/
[Link]
projectname/
__init__.py
[Link]
[Link]
[Link]
[Link]
[Link] : Command-line utility for managing the project.
[Link] : Configuration settings for the project.
[Link] : Routes and URL configuration.
[Link] and [Link] : ASGI/WSGI application settings for deployment.
Alternatively:
django-admin startproject projectname .
What it does: Initializes the Django project in the current directory instead of creating a new folder.
Step 5: Check Base Setup
python [Link] check
What it does: Validates your project setup for any issues like configuration errors. It should return
System check identified no issues (0 silenced) .
Step 6: Run the Development Server
python [Link] runserver
What it does: Starts a development server at [Link] . This allows you to check the
project in a browser. Visit the URL, and you should see Django's default welcome page.
Step 7: Create Database Migrations
python [Link] makemigrations
What it does: Creates migration files based on the database models you define. These files are
instructions for updating the database schema.
Step 8: Apply Migrations
python [Link] migrate
What it does: Applies the migration files to the database, creating or updating tables. For a new project,
this sets up the default database tables Django needs (e.g., for user authentication).
Step 9: Create a Superuser
python [Link] createsuperuser
What it does: Creates an admin user to manage the site via Django's admin interface. You'll be
prompted to enter:
Username: admin (or your choice)
Email: admin@[Link] (or your choice)
Password: admin (or your choice)
Summary Workflow
1. Set up and activate a virtual environment to isolate dependencies.
2. Install Django.
3. Start a new project with django-admin startproject .
4. Check that the project is functional with check and runserver .
5. Configure and set up the database with migrations.
6. Create a superuser for admin tasks.
You can now access the admin panel at [Link] using the superuser credentials!
Create another user and check if it reflects in [Link]