Having difficulty in creating your first project in Django?
Don't worry. This tutorial will guide you to set up an environment for creating and launching your first project.
Django is a powerful Web application framework that lets you do everything rapidly—from designing and developing the original application to updating its features and functionality. It was built using Python, an object-oriented applications development language that combines the power of systems languages, such as C/C++ and Java.
In this tutorial, you’re going to learn how to set up a Django project on your machine. This tutorial is made for beginners with no prior knowledge of Django required.
Table of Contents
- Why use Django Framework
- Setting Up Django Project
- Project Directory
- Running the Server
- Launching the Project
This tutorial assumes you have the following requirements fulfilled in order to follow along:
- You are on a Windows 10 or greater computer with python latest version installed on it. This tutorial will use a computer with Windows 10 and python version 3.8.
- An IDE of your choice such as Visual Studio Code or PyCharm Community Edition. This tutorial will use the Visual Studio Code. You will use it for verifying the successful creation of your project.
Why using Django Framework?
Django was released as an open-source project when it was widely felt that Python had far too many web frameworks—and rapidly gained a strong following. It reduces the amount of code and results in faster development.Today, it is one of the leaders not just among Python frameworks, but among Web frameworks in general.
Companies and organizations around the world have picked it up for use in projects large and small. A partial list includes
- The Washington Post
- The Lawrence Journal-World
- Open the Command Prompt and type the following command.
py -m pip install Django
- From the Command Prompt, navigate to the desired directory where you wanted to create the project. This tutorial will create a Django project named DjangoApp in the directory DjangoProjects located at Desktop.
- Change the path to Desktop by typing the following command.
- Type the following command to create a directory named DjangoProjects.
This will create a folder named DjangoProjects on the desktop. Now, you need to go inside the folder to create Django Project.
- Type the following command to move inside the directory.
- The command prompt will look like this:
Setting Up Django Project
- Type the following commands:
django-admin startproject DjangoApp
This will create a DjangoApp directory in your current directory and changes the current directory to DjangoApp.
- Open VS Code and navigate to the location where DjangoApp is located. In this case, it will be located at the following location: Desktop > DjangoProjects > DjangoApp.
- Select the folder and open it.
The project structure will look like this:
Running the Server
- Let’s verify your Django project works. Run the following commands:
python manage.py runserver
- You will see the following output on the command line:
Launching the project
Now that the server’s running, visit http://127.0.0.1:8000/ with your Web browser. You’ll see a “Congratulations!” page, with a rocket taking off.