Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install Django on Windows, let’s briefly understand - What is Django ?

Django is a powerful framework useful for writing Python web applications. It is full of features that allow getting your applications as well as sites up. It's a framework that lets you focus on the unique portions of the application, even let the tools do the heavy lifting.

In this tutorial, you will install Django on Windows. We will also address a few FAQs on how to install Django on Windows.

Advantages of Django

  1. Rapid development: Django's built-in features and utilities allow for faster development of secure and scalable web applications.
  2. Pythonic simplicity: Django's intuitive design and clean syntax make it easier to write and maintain code, resulting in increased productivity.
  3. Batteries included: Django comes with numerous ready-to-use components and plug-ins, reducing the need for third-party libraries and saving development time.
  4. Excellent documentation: Django provides thorough and well-organized documentation, making it easier for developers to learn and implement the framework.
  5. Robust security: Django includes various security features, such as user authentication and protection against common web vulnerabilities, ensuring the safety of web applications.

Prerequisites

  • Make sure you have Python installed on your system.
  • PowerShell
ℹ️
The commands mentioned in this article are tested on Powershell. Most of them will work on Windows Command Prompt (CMD) as well with a few exceptions but for a smooth experience, we would recommend using Powershell.

Step 1 - Open Powershell

1) Firstly, you need to open Powershell. There are two ways in which you can do that. Either search for Powershell in the Windows search box or open the Run dialog box with (WIN+R). Once the dialog box is open, type Powershell and click OK.

Once the Powershell window is open, you will verify Python installation in the next section.

Step 2 - Verify Python Installation

Before installing Django, you need to make sure that Python is installed on your system.

Type the following command to verify the installation:

python -V

You will get the below output:

Output

PS C:\Users\Username> python -V
Python 3.9.7

At the time of writing this article, I have Python version 3.9.7 and yours may be different, but the output will confirm if you have Python installed or not.

Step 3 - Upgrade Pip  

Pip comes by default with Python but generally with an old version. Use the following command to upgrade pip:

python -m pip install --upgrade pip

Step 4 - Create Project Directory

Now, create a project directory in which you will keep the Django repository. Name the project based on your choice.

1) cd into your Desktop directory:

cd Desktop

2) Use the following command to create a directory:

mkdir demo_project

3) Now, enter the newly-created directory using the below command:

cd demo_project

Step 5 - Create a Virtual Environment

1) In this step, you will create a virtual environment for you project. With the help of a virtual environment, you can create an isolated environment that won't affect other Python projects.

If you are not using a virtual environment, all your projects will be using the same Django version installed globally. It can lead your projects to fail when there is an update in Django with breaking changes.

Use the following command to create a virtual environment:

python -m venv venv

The above command will create a directory called venv inside your project directory.

Confirm if the venv directory has been created using the below command:

ls

Step 6 - Activate the Virtual Environment

1) Now, you will activate the virtual environment in your directory.

Run the following command:

venv\Scripts\activate

Once, it is activated you will see venv at the beginning:

(venv) PS C:\Users\Stanley\Desktop\django_project>

Step 7 - Install Django on Windows

1) You will be installing Django using pip, execute the following command:

pip install django

The above command will install the latest version of Django.

2) In case you want to install a different Django version, mention the version as follows:

pip install django==3.1

3) Now, verify if the installation has been done successfully:

django-admin --version

4) You will get an output like below:

Output 

PS C:\users\stanley\Desktop\django_project> django-admin --version
3.9.7

Step 8 - Create a Django Project

1) You can create your first Django project using the following command:

django-admin startproject test_project

2) Move to the test_prohect:

cd test_project

3) Type the following command to see the contents of the project directory:

ls test_project

Step 9 - Run the Development Server

1) Once the project is created, start the Django development server:

python manage.py runserver

2) Now, you can access your project at http://127.0.0.1:8000/.

3) If you want to stop the server, press CTRL+C  and to deactivate the virtual environment type deactivate.

FAQs to Install Django on Windows

Is it necessary to create a virtual environment for Django?

Although not mandatory, it is recommended to create a virtual environment to isolate your Django project's dependencies and avoid version conflicts with other projects.

How do I create a virtual environment on Windows?

Open the command prompt, navigate to your project's directory, and run python -m venv env to create a virtual environment named "env".

How do I activate the virtual environment on Windows?

In the command prompt, navigate to your project's directory and run .\env\Scripts\activate to activate the virtual environment.

Can I install Django inside a virtual environment?

Yes, activate the virtual environment, then use pip install django to install Django specifically within that environment.

How do I start a new Django project on Windows?

Navigate to your desired project directory, activate the virtual environment, and run django-admin startproject projectname to create a new Django project.

How do I run the Django development server on Windows?

Navigate to the project directory where the 'manage.py' file is located. Activate the virtual environment and run python manage.py runserver to start the development server.

How can I verify if Django is correctly installed on Windows?

Open the command prompt, navigate to your project directory, activate the virtual environment, and run python -m django --version. It will display the installed Django version if it is installed correctly.

Conclusion

We hope this detailed tutorial helped you to install Django on Windows.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.