Django is one of the most popular Python web frameworks, used by developers worldwide to build robust, scalable, and secure web applications.
If you're a beginner or an experienced developer looking to set up Django on your Windows machine, this step-by-step guide will walk you through the entire process. By the end of this tutorial, you'll have Django installed and ready to create your first project.
Before installing Django, ensure your system meets the following requirements:
Windows Operating System: This guide assumes you’re using Windows 10 or later.
Python Installed: Django requires Python. Make sure you have Python installed (preferably Python 3.8 or higher).
Basic Command-Line Knowledge: You’ll need to use the Command Prompt or PowerShell for some steps.
Django is a Python-based framework, so the first step is to install Python on your system.
Open the Command Prompt or PowerShell and type:
python --version
If Python is installed, you’ll see its version number (e.g., Python 3.10.5). If not, proceed to the next step.
Visit the official Python website: https://www.python.org/downloads/.
Download the latest stable release for Windows.
Run the installer and follow these steps:
Check the box that says "Add Python to PATH" during installation.
Click "Customize installation" and ensure all optional features (like pip) are selected.
Complete the installation process.
After installation, confirm Python and pip (Python’s package manager) are working:
python --version
pip --version
A virtual environment allows you to manage project-specific dependencies without affecting your global Python setup.
Run the following command to install the virtualenv package globally:
pip install virtualenv
Navigate to the directory where you want to create your Django project and run:
virtualenv myenv
Here, myenv is the name of your virtual environment. You can choose any name.
To activate the virtual environment:
On Command Prompt:
myenv\Scripts\activate
On PowerShell:
.\myenv\Scripts\Activate
Once activated, you’ll see (myenv) appear at the beginning of your command prompt.
With the virtual environment activated, you can now install Django using pip.
Run the following command:
pip install django
To confirm Django is installed, check its version:
django-admin --version
You should see the installed Django version (e.g., 4.2.5).
Now that Django is installed, let’s create a new project.
Run the following command to create a new Django project:
django-admin startproject myproject
Here, myproject is the name of your project. Replace it with your desired project name.
Move into the project folder:
cd myproject
Django comes with a built-in development server that allows you to test your application locally.
Execute the following command:
python manage.py runserver
Open your web browser and go to:
http://127.0.0.1:8000/
You should see the default Django welcome page, confirming that your setup is working correctly.
Once you’re done working on your project, you can deactivate the virtual environment by simply running:
deactivate
This will return you to your global Python environment.
Depending on your project requirements, you might want to install additional tools or libraries:
Database Drivers: For example, PostgreSQL (psycopg2) or MySQL (mysqlclient).
Frontend Frameworks: Use libraries like Bootstrap or Tailwind CSS for styling.
Debugging Tools: Install packages like django-debug-toolbar for debugging.
Install these tools in your virtual environment using pip:
pip install package_name
If you encounter an error like 'python' is not recognized, ensure Python was added to your system’s PATH during installation. You can manually add it by editing the system environment variables.
On some systems, PowerShell may block scripts from running. To fix this, run the following command as Administrator:
Set-ExecutionPolicy RemoteSigned
If port 8000 is already in use, specify a different port when running the server:
python manage.py runserver 8080
Congratulations! You’ve successfully installed Django on your Windows machine and created your first project. Django’s simplicity and power make it an excellent choice for building web applications, from small personal projects to large-scale enterprise solutions.
Now that your environment is set up, you can dive deeper into Django’s features, such as creating apps, defining models, and building APIs. Happy coding!
Have questions or ran into issues during installation? Let us know in the comments below—we’d love to help!
Before diving into the installation, ensure you have the following prerequisites installed on your system:
Python: Django is a Python web framework, so you need to have Python installed. Download the latest version from the official Python website and follow the installation instructions.
PIP (Python Package Installer): PIP is the package installer for Python. It usually comes bundled with Python, so you should have it available after installing Python. You can verify its installation by opening a command prompt and typing pip --version.
To begin the installation, open a command prompt on your Windows machine. You can do this by pressing Win + R, typing cmd, and hitting Enter.
Creating a virtual environment is a good practice to keep your project dependencies isolated. To install the virtual environment package, run the following command:
pip install virtualenv
Navigate to the directory where you want to create your Django project and run the following commands to create and activate a virtual environment:
cd path\to\your\project
virtualenv venv
venv\Scripts\activate
Replace path\to\your\project with the actual path to your project directory.
With the virtual environment activated, you can now install Django using PIP:
pip install django
This command will download and install the latest version of Django and its dependencies.
Related Posts:
How to install Django on Windows
How to install Django on Linux
How to create a Django project
How to Run Your First Django Project
How to Set Up a Virtual Environment for Django
How to Install Django in a Virtual Environment
How to Understand the Django Project Structure
How to Configure Django Settings
How to Use the Django Admin Interface
How to Create and Apply Django Migrations
How to Define Models in Django
How to Create Django Templates
How to Use Static Files in Django
How to Implement Django ModelForms
How to Create Django Class-Based Views
How to Implement Django Function-Based Views
How to Handle User Authentication in Django
How to Create Custom Django User Models
How to Implement Django Celery for Background Tasks
How to Use Django with SQLite Database
How to Connect Django to MySQL
To ConfirmA I'm that Django has been successfully installed, run the following command:
python -m django --version
This should display the installed Django version, indicating a successful installation.
Now that Django is installed, you can create a new Django project using the following command:
django-admin startproject yourprojectname
Replace yourprojectname with the desired name for your Django project.
Move into the newly created project directory:
cd yourprojectname
To verify that your Django installation is functioning correctly, start the development server with the following command:
python manage.py runserver
This will launch the development server, and you can access your Django project by navigating to http://127.0.0.1:8000/ in your web browser.
Congratulations! You have successfully installed Django on your Windows machine and created a new Django project. From here, you can start building your web applications with the powerful features that Django has to offer.