Home Django How to install Django on Windows

How to install Django on Windows

There’s no doubting the popularity of the Django framework when it comes to web development. As a matter of fact, you can expect it to get even more attention in the future because it gets updated so frequently. And, not to mention, this framework also has to bring to the table security, reusability, and rapid development. With that being said, if you’re interested in learning more about Django, you should click this link to have a better idea of what this web framework is all about.

Although it is generally considered that programmers should prefer using Linux for their work, there is no reason you shouldn’t code on your Windows system either. And, this case is particularly true when it comes to the Django web framework. After all, it is based on the Python programming language, which happens to be cross-platform and supports Windows quite well.

Installing Django on Windows

Regardless of whether you’re migrating to a Windows-based system or want to give a shot to the Django framework, the good news is that installing Django on Windows is quite easy, and today we’re going to show you how.

As you might already know, Django is based on the Python programming language. Considering this, you would have to install it on your system if you haven’t already.

Step 1 – Download Python

The first thing you need to do is download the latest Python version from its official website here. Once you’re done with that, you need to run the installer and tick the boxes alongside “Install launcher for all users (recommended)”. Lastly, click on the ‘Install Now’ button to start the installation procedure.

Step 2 – Check Python version

When the installation finishes, you need to open the command prompt by searching for it in the Start menu or pressing the Windows key and R (Win+R) to open the Run dialog box to type ‘cmd’ and hit Enter.

Opening-Command-Prompt
Opening Command Prompt

Lastly, the following command needs to be executed:

py --version

With this, you’ll be able to make sure that your system has the same version of Python as you installed.

Once Python has been installed on your system, you will be able to use its package manager called pip. Courtesy of pip, installing, and uninstalling Django and other Python packages become possible with a little help from the command prompt.

Step 3 – Upgrade Python to the latest version

It is often the case that Python comes with older versions of pip, which could create unneeded complications. What you need to do here is get the latest version of pip by executing the following command:

python -m pip install --upgrade pip
Upgrading-pip
Upgrading pip

Step 4 – Setting up a Virtual Environment

Before we get to installing Django, there’s another step that we recommend taking, which is to set up a virtual environment. When it comes to web development with Django, it is usually the case that a dedicated environment is provided to each Django project.

Hence, you should open the command prompt once again and head to the directory where you’d like the Django project to be. Afterward, the following command needs to be executed:

py -m venv first-project

This command should create a new virtual environment within the folder called ‘first-project’. However, this environment needs to be activated and you can do so with the following command:

first-project\Scripts\activate.bat
Setting-Up-Virtual-Environment
Setting Up Virtual Environment

Once you run this command, the virtual environment should be activated with “(project-name)” mentioned alongside the command prompt.

Another thing worth mentioning here is that you’d need to activate this environment every time you open a new command prompt.

Step 5 – Install Django

Now that you’re in an active virtual environment, you can install Django in it simply with the help of the following command:

py -m pip install Django
Installing-Django
Installing Django

Right after you execute this command, the Django web framework’s latest version should start getting downloaded and installed on your Windows machine automatically. Yes, this one command is all it takes to install Django on your computer.

Step 6 – Check Django version

There’s another additional step that we suggest you take to make sure that Django has been successfully installed. The following command should let you know which version of Django is installed on your device:

django-admin --version

Step 7 – Installing Specific Django Version

It is also possible to install a specific version of Django. So, if you’d like to have a taste of Django 2.1, you can get it with the following command:

pip install django==2.1

Step 8 – Create your first Django Project

Now that you’ve successfully installed Django, creating your first Django project (by the name of ‘testsite’) would also become possible with one simple command:

django-admin startproject testsite

Not only that, but you can also get your site up and running just as easily. First of all, you’d have to get into your project directory by executing:

cd testsite

After that, you just need to run one more command to get your development server running:

python manage.py runserver
Running-Local-Server
Running Local Server

With this, you should be able to have an up and running website that you can check out by visiting http://localhost:8000/ in your web browser.

Visiting-Testsite
Visiting testsite

Although it’s normally not the case, it is possible that you can come across an issue while installing Django on Windows-based systems. So, if you’re getting stuck in any of the aforementioned steps, click here to read the detailed guidelines on how to install Django on Windows.

Conclusion

There’s no denying the fact that Django is one of the best web frameworks out there right now, and everyone wants to get their hands on it. However, what makes this framework even better is the fact that it cuts down all the complications. Accordingly, as you might have seen from this article, installing Django on Windows-based systems is no more than child’s play. And, once your installation completes, you can start delving into the basics of this amazing web framework.

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More