Paramclasses Academy - Blog

Tutorials Details

Django Installation and Environment Setup: Step-by-Step Guide

Django Installation and Environment Setup: Step-by-Step Guide

October 19, 2026

Django Installation and Environment Setup: Step-by-Step Guide

Introduction

Before developing websites with Django, we need to prepare our computer with the necessary software and development tools.

Django is a high-level web framework written in Python. It provides tools for URL routing, database operations, HTML templates, authentication, and web application development.

In this tutorial, you will learn how to install Python, create a virtual environment, install Django, verify the installation, and create your first Django project.

By the end of this tutorial, you will have a working Django development environment on your computer.

What Do You Need Before Installing Django?

Before starting, make sure you have the following:

  1. A computer running Windows, macOS, or Linux.

  2. Python installed on your computer.

  3. A terminal or command prompt.

  4. An internet connection for downloading the required packages.

  5. A code editor such as Visual Studio Code (VS Code).

Important: Install a Python version supported by the Django version you plan to use. Check Django's official documentation for version compatibility.

Step 1: Install Python

Python is the programming language used to write Django applications.

How to Install Python on Windows

  1. Visit the official Python website: python downloads

  2. Download a compatible Python installer for Windows.

  3. Run the downloaded installer.

  4. Select the option Add Python to PATH, if available.

  5. Click Install and wait for the installation to finish.

After installation, open Command Prompt and run:

python --version

On some Windows installations, use:

py --version

Example output:

Python 3.x.x

The exact version number depends on the Python version installed on your computer.

If the command is not recognized, check the installation and PATH settings.

Step 2: Create a Project Folder

Create a dedicated folder for your Django practice projects.

For example, create a folder named django_learning on your computer.

Open Command Prompt and navigate to that folder. If you created it on your G drive, use:

G:
cd \django_learning

You can use a different location according to your preference.

Keeping your project files organized makes development and maintenance easier.

Step 3: Create a Virtual Environment

A virtual environment keeps the Python packages for one project separate from packages installed for other projects.

This helps avoid dependency conflicts when different projects require different package versions.

Create a virtual environment by running:

python -m venv venv

If your Windows system uses the Python launcher, you can also run:

py -m venv venv

This creates a folder named venv inside your current project directory.

Activate the Virtual Environment

On Windows Command Prompt:

venv\Scripts\activate

On Windows PowerShell:

.\venv\Scripts\Activate.ps1

If PowerShell blocks script execution, review your execution policy and use a safe, appropriate activation method rather than changing security settings unnecessarily.

When activation succeeds, the terminal usually displays (venv) before the command prompt.

Step 4: Install Django

After activating your virtual environment, install Django using pip:

python -m pip install Django

This installs a Django version compatible with your Python environment.

To check the installed version, run:

python -m django --version

Example output:

5.x

The actual version may differ depending on the version installed.

Note: For a new project, check the official Django release and compatibility documentation before selecting a version.

Step 5: Create Your First Django Project

Now that Django is installed, create a new project.

Run the following command in your project directory:

django-admin startproject myproject .

The final dot (.) tells Django to create the project files in the current directory.

Alternatively, you can run:

django-admin startproject myproject

This creates a separate directory named myproject.

Choose one approach and follow its corresponding folder structure.

Important Django Project Files

A typical Django project contains these files:

manage.py: A command-line utility used to run project management commands.

settings.py: Contains project configuration, including installed apps, database settings, templates, and other settings.

urls.py: Defines URL patterns that connect incoming requests to the appropriate views.

asgi.py: Provides the ASGI application entry point.

wsgi.py: Provides the WSGI application entry point.

These files work together to configure and run your Django website.

Step 6: Run Database Migrations

Django includes built-in applications that use database tables for features such as authentication and administration.

Before using these features, run:

python manage.py migrate

Django applies the migrations required by the project's installed applications.

A new project commonly uses SQLite by default. You can configure another supported database when your project requires it.

Step 7: Start the Django Development Server

Run the following command:

python manage.py runserver

If the server starts successfully, the terminal displays a local development address, commonly:

http://127.0.0.1:8000/

Open this address in your web browser.

You should see Django's default welcome page when the project has been created and configured successfully.

Important: The development server is intended for local development and testing. Do not use it as the production server for a live website.

Step 8: Create a Django App

A Django project can contain multiple apps. Each app usually handles a particular feature or area of functionality.

For example, a student management project might contain apps for students, courses, and attendance.

Stop the development server with Ctrl + C in the terminal, then run:

python manage.py startapp students

This creates a Django app named students.

A typical app contains files such as:

  • models.py — defines data models.

  • views.py — handles request processing.

  • admin.py — configures models for the Django admin interface.

  • apps.py — contains app configuration.

  • tests.py — contains automated tests.

  • migrations/ — stores database migration files.

To use the app as an installed application, add 'students' to INSTALLED_APPS in settings.py.

Step 9: Verify Your Setup

Use this checklist to verify that your environment is ready:

  1. Python is installed.

  2. The virtual environment is activated.

  3. Django is installed.

  4. The Django version command works.

  5. The project has been created.

  6. Database migrations run successfully.

  7. The development server opens in your browser.

  8. The students app has been created.

If any step fails, read the terminal error carefully and check the relevant installation or configuration.

Common Installation Errors and Solutions

Error 1: Python Is Not Recognized

Cause: Python may not be installed correctly or its executable may not be available through PATH.

Solution: Verify the installation and try py --version on Windows.

Error 2: No Module Named Django

Cause: Django may not be installed in the active Python environment.

Solution: Activate the correct virtual environment and run:

python -m pip install Django

Error 3: Virtual Environment Activation Fails

Cause: The activation command may not match the terminal being used.

Solution: Use the Command Prompt or PowerShell activation command shown earlier in this tutorial.

Error 4: Port 8000 Is Already in Use

Cause: Another application may already be using the default development port.

Solution: Start Django on another port:

python manage.py runserver 8001

Then open http://127.0.0.1:8001/ in your browser.

Error 5: Migration Errors

Cause: Database configuration, migration files, or installed application settings may be incorrect.

Solution: Read the complete error message and verify your database configuration before changing or deleting migration files.

Frequently Asked Questions (FAQs)

Q1. What is required to install Django?

Answer: You need a compatible Python installation, pip, and a terminal. A code editor is also useful.

Q2. Is Django installed separately from Python?

Answer: Yes. Python is the programming language, while Django is a framework installed as a Python package.

Q3. Why should we use a virtual environment?

Answer: It isolates project dependencies and helps prevent package conflicts between projects.

Q4. What is pip?

Answer: pip is a Python package installer used to install and manage packages such as Django.

Q5. What is the purpose of manage.py?

Answer: It runs Django management commands for tasks such as starting the development server, creating apps, and applying migrations.

Q6. What is the default Django development URL?

Answer: It is commonly http://127.0.0.1:8000/.

Q7. What is the difference between a Django project and an app?

Answer: A project contains the overall website configuration, while an app provides a specific set of features.

Q8. Can Django run without a separate database server?

Answer: Yes. A new Django project commonly uses SQLite, which does not require a separate database server.

Q9. Is Django's development server suitable for production?

Answer: No. A live website should use a production-appropriate deployment setup.

Q10. How can I check the installed Django version?

Answer: Run python -m django --version in the appropriate Python environment.

Important Interview Questions and Answers

Q1. How do you install Django?

Answer: Create and activate a virtual environment, then run python -m pip install Django.

Q2. What is a virtual environment?

Answer: It is an isolated Python environment used to manage project-specific dependencies.

Q3. What is the purpose of startproject?

Answer: The startproject command creates the initial Django project structure and configuration files.

Q4. What does startapp do?

Answer: It creates the initial structure for a Django application.

Q5. Why do we run migrate?

Answer: It applies database migrations for installed applications.

Q6. What is the purpose of runserver?

Answer: It starts Django's development server for local testing.

Q7. What is settings.py?

Answer: It contains the project's configuration settings.

Q8. What is urls.py?

Answer: It defines URL patterns used to route incoming requests.

Q9. What is the difference between WSGI and ASGI?

Answer: WSGI is a standard interface for synchronous Python web applications, while ASGI supports asynchronous application interfaces and related capabilities.

Q10. Why should the development server not be used for production?

Answer: It is designed for development and does not provide the production deployment setup required for a live application.

Conclusion

In this tutorial, you learned how to install Python and Django, create a virtual environment, install packages, create a Django project, apply migrations, start the development server, and create your first app.

These steps provide the foundation for building database-driven websites and web applications with Django.

In the next tutorial, you will learn about Django Project Structure and Important Files, including how settings.py, urls.py, manage.py, and app files work together.