How To Install And Launch Django On Your Windows PC

Viktor Nagornyy
Powered by Django
Published in
5 min readMar 19, 2023

--

Django is a robust web framework for Python, and it can be installed and launched on your Windows PC to help you build your app quickly before deploying it to the cloud and accepting user sign-ups.

For this tutorial, we’ll be using pipenv, a tool that simplifies the management of dependencies and virtual environments.

Follow these step-by-step instructions on how to install and launch Django on Windows using pipenv.

Before We Begin

Make sure you have the following prerequisites installed on your Windows machine to follow the instructions:

Are you getting the “Python is not recognized” error? The fix is here ›

We will use the built-in Command Prompt (CMD) for this tutorial. You can search for CMD to open it using Windows search.

Command Prompt

If you don’t have pipenv installed, you can install it by running the following command in your CMD after Python was installed:

pip install pipenv

Once these prerequisites are installed, you can install and launch Django.

Step 1: Create a new project directory

Open your CMD and create a new directory for your Django project. You can do this by running the following command:

mkdir myproject

Change your current directory to the newly created directory by running:

cd myproject

Step 2: Install Django using Pipenv

To install Django using pipenv, run the following command:

pipenv install django

This command will create a new virtual environment for your project and install Django and its dependencies within this environment.

Step 3: Launch the pipenv shell

pipenv shell

This command will activate the virtual environment created in the previous step, and you’ll see the name of the environment displayed in your CMD.

Virtual environment name

To exit pipenv virtual environment, type in exit. That will terminate the virtual environment, so you won’t see its name in the CMD anymore.

Step 4: Create a new Django project

The following commands must be executed while your virtual environment is active. Otherwise, they won’t work.

To create a new Django project, run the following command:

django-admin startproject myproject .

This command will create a new Django project named “myproject” in the current directory (note the . dot at the end of the command).

This command doesn’t have any output. So if you don’t see anything after executing it, don’t worry. A new directory named “myproject” with Django files will be created. That’s how you know it worked.

Step 5: Launch the development server

To launch the development server, navigate to the root directory of your project (where the manage.py file is located) and run the following command:

python manage.py runserver

Are you getting the “No module named ‘django’ ” error? The fix is here ›

This command will start the development server, and you’ll see output similar to the following:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

March 19, 2023 - 10:30:52
Django version 4.1, using settings 'myproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

This output indicates that the development server is running and listening for incoming connections on port 8000.

Open your browser and go to http://127.0.0.1:8000/ to see Django’s page:

Django app’s homepage

If you see this page in your browser, Django has been successfully installed and runs using the development server.

Any changes to the code will be picked up automatically, and Django’s server will reload Django when it detects changes.

While the server is running, you can see errors as they happen while Django’s server reloads everything. If you made a typo and crashed the app, you will see the error in CMD. It’s very helpful to troubleshoot problems.

Quit Development Server

You need to know how to quit Django’s development server. The instructions provided in the CMD state:

Quit the server with CTRL-BREAK

The problem is Windows doesn’t have BREAK.

To quit the Django server, use CTRL+C instead.

To Sum Up

In this article, I’ve provided step-by-step instructions on installing and launching Django on Windows using pipenv. With these instructions, you should be able to get up and running with Django quickly and easily.

If you want to be notified of new stories related to Django, follow Powered by Django here on Medium, or you can follow me to learn more about digital marketing in addition to Django.

Below, I’ve included fixes for the two most common errors beginners face when setting up and launching Django. Leave a clap if it helps you!

Windows CMD: “Python is not recognized”

If this was the first time installing Python, you may see this error when executing Python commands in CMD:

'python' is not recognized as an internal or external command,
operable program or batch file.

This usually happens because Windows doesn’t know where python.exe is located, and we need to set the PATH manually. To fix this error, follow the instructions in this tutorial:

ModuleNotFoundError: No module named ‘django’

This is an error you will see when you try to run Django’s server, but your pipenv virtual environment is not active.

You need to activate the virtual environment first:

pipenv shell

Then run Django’s server.

--

--

Viktor Nagornyy
Powered by Django

📈 Marketing consultant. 14 years helping biz generate leads & sales. Open source advocate. Sign up for my marketing coaching newsletter ➡️ inboundmethod.com/m