0% found this document useful (0 votes)
32 views

Django

Uploaded by

22pw03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Django

Uploaded by

22pw03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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/
manage.py
projectname/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py

manage.py : Command-line utility for managing the project.


settings.py : Configuration settings for the project.
urls.py : Routes and URL configuration.
asgi.py and wsgi.py : 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 manage.py 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 manage.py runserver

What it does: Starts a development server at http://127.0.0.1:8000/ . 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 manage.py 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 manage.py 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 manage.py 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@admin.com (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 http://127.0.0.1:8000/admin/ using the superuser credentials!
Create another user and check if it reflects in db.sqlite

You might also like