banner



How To Install Python Django On Windows 10

Introduction

The Python ecosystem has a lot of web frameworks. Ane that has consistently been popular is the Django framework. It's pop for being robust, secure, and allows developers to develop projects fast and meet their deadlines. It is free and open-source, and information technology works on both Windows and *nix systems.

In this tutorial, you lot will learn how to install Django on Windows using pip. After that, you lot will verify the installation, create a project, and start a Django evolution server.

Prerequisites

Before you install Django, you must make certain that Python is installed on your arrangement. Yous tin can check out this guide — how to install python on windows to learn how to exercise it.

The commands that you will run in this tutorial were tested on the PowerShell shell, but most commands should work on Windows Command Prompt(CMD) with a few exceptions. For a smooth experience, I would suggest yous use PowerShell for this tutorial.

Step ane — Opening PowerShell

First, you need to open PowerShell on your computer. You can exercise that past searching for PowerShell in the Windows search box or you lot tin can open the Run dialog box past holding the Windows logo key and R(WIN+R). Once the dialog is open up, type powershell, and and then click OK.

You should now accept the PowerShell window opened.

powershell opened

Now that you have opened PowerShell on your computer, you'll verify the installation of Python in the adjacent department.

Pace ii - Verifying Python Installation

Before you install Django, first, y'all demand to make sure that you lot installed Python on your arrangement.

To practice that, blazon the following command in PowerShell prompt to verify the installation:

-5 option logs the Python version installed on your organization.

Subsequently running the command, you should run across output like this:

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

At the fourth dimension of writing, it is Python 3.nine.7. You might have a dissimilar version from mine, and that's fine. As long as you run across the Python version logged, Python is installed on your system.

At present that you've confirmed Python is installed on your system, you will upgrade pip.

Pace 3 - Upgrading Pip

Python comes with pip by default. But most of the fourth dimension, it comes with an old version. it's ever a proficient practice to upgrade pip to the latest version.

Enter the following control to upgrade pip on your system:

            > python -chiliad pip install --upgrade pip                      

You lot'll get output identical to the post-obit screenshot showing you that the upgrade was a success:

upgrade pip

Now you lot've upgraded pip, you lot'll create the projection directory where you'll install Django.

Step 4 - Creating a Project Directory

In this department, you volition create a directory that will contain your Django application. Nosotros will name information technology django_project since this tutorial is a demo. But in a real projection, you tin can give the directory a suitable name, such as forum, web log, etc.

Change into your Desktop directory with the cd control:

Create the directory using the mkdir command:

Move into the django_project directory using the cd command:

Your prompt should at present show you that you're in the django_project directory as shown in the following output:

                          PS                                          C:\Users\Stanley\Desktop\django_project              >                                                  

At present that you've created the working directory for your projection, you lot'll create a virtual environment where you'll install Django.

Step 5 - Creating the Virtual Environment

In this step, you lot'll create a virtual environment for your project. A virtual environment is an isolated environs in Python where you can install the project dependencies without affecting other Python projects. This lets you create different projects that use different versions of Django.

If you don't use a virtual environment, your projects in your organisation will use the same Django version installed globally. This might wait like a skilful thing until the latest version of Django comes out with breaking changes causing your projects to neglect altogether.

You tin can learn more than about the virtual environment by following Python Virtual Environments: A Primer.

To create a virtual environment, blazon the post-obit command and wait for a few seconds:

The command will create a directory chosen venv within your project directory.

Next, confirm the venv directory has been created by listing the directory contents using the ls command:

You should see the directory venv in the output as shown in the following screenshot:

verify that venv directory is created

At present you've created the virtual environment directory, you'll actuate the environment.

Step half dozen - Activating the Virtual Surroundings

In this section, you'll activate the virtual environment in your directory.

Run the post-obit command to activate the virtual surround:

After you run the command, you volition run into

a (venv) at the beginning of the prompt. This shows that the virtual environment is activated:

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

If you see the error shown in the following screenshot on PowerShell when activating the virtual environment, for the sake of brevity, I described the reason and the solution in another post. Follow Solution to "Running Scripts Is Disabled On This Arrangement" Error on PowerShell and don't close your PowerShell:

activation error

Now that you've activated the virtual environment for your project, the moment you've been waiting for is hither. It'southward time to install Django!

Step vii - Installing Django

In this section, you lot will install Django on your system using pip.

Run the following command to install Django using pip install:

            (venv)> pip install django                      

The command will install the latest version of Django. Y'all should see Django being downloaded as shown in the following screenshot:

django installing

If you want to install a dissimilar Django version, you lot can specify the version as follows:

            (venv)> pip install django==iii.1                      

Once the installation finishes, you need to verify that Django has been installed. To practise that, type the following control:

            (venv)> django-admin --version                      

You lot volition become output showing y'all the Django version installed on your system:

                          (              venv              )                                          PS                                          C:\users\stanley\Desktop\django_project              >                                          django-admin                                          --version                                          3.2              .              seven                                                  

At the time of writing, the latest Django version is 3.2.7, and that'southward why my output shows that.

Y'all've now installed Django on your organization, great chore! You'll begin to create a Django project.

Footstep 8 - Creating the Django Project

At present it's fourth dimension to create a project. A project has a different meaning from what you may be used to. The Django documentation defines information technology as:

A Python packet – i.e. a directory of code – that contains all the settings for an instance of Django. This would include database configuration, Django-specific options and application-specific settings.

You lot create a project past using the command-line utility django-admin that comes with Django. The command generates files where you tin can configure the settings for your database, add third-political party packages for your project to mention a few.

Create the project using the django-admin startproject command:

            (venv)> django-admin startproject test_project                      

Change into the test_project directory:

Type the following command to encounter the contents in the project directory:

You will get output similar to this:

            (venv) PS C:\users\stanley\Desktop\django_project\test_project> ls     Directory: C:\users\stanley\Desktop\django_project\test_project  Mode                LastWriteTime         Length Name  ----                -------------         ------ ----  d-----         9/4/2021   1:25 AM                test_project  -a----         9/4/2021   1:25 AM            690 manage.py                      

The directory test_project contains Django configuration files. The manage.py file comes in handy when starting a development server, and that'south what you will practise in the adjacent footstep.

Step nine - Running the Development Server

Now that the project has been created, we will starting time the Django development server.

Start the development server using the manage.py runserver command:

            (venv)> python manage.py runserver                      

run server

Side by side, visit http://127.0.0.1:8000/ in your web browser. You lot should see a page similar to the following screenshot:

server running

Tip You lot can stop the server by belongings CTRL+C. To deactivate the virtual environment, you can type deactivate on the prompt.

Now, you lot are ready to first developing your projection.

Conclusion

Yous have come up to the end of this tutorial, you learned how to install Django on Windows, verifying the installation and yous likewise learned how to create a Django projection, and start a development server. You tin can visit Django'southward official tutorial to learn how to build an application, meet Writing your first Django app, part 1.

Thank you for reading and don't forget to follow me on Twitter for more tips.

Source: https://www.stanleyulili.com/django/how-to-install-django-on-windows/

Posted by: huntyournothed.blogspot.com

0 Response to "How To Install Python Django On Windows 10"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel