Hello Programmers, This is going to be one of the most exciting tutorials because in this article we will create the first Django project from scratch and explore all its files and directory. In the previous tutorial, we have seen all about Django architecture.
Headings of Contents
First Django Project
Here we’ll go through fairly simple steps to get up and running our first Django applications.
- Create a folder, Here we are creating a folder using
mkdir Django project
cd Django project
- Create Python virtual environment that is an isolated Python environment.
python -m venv venv_name
In the above command,
venv_name represents the name of the Python virtual environment.
- Activate Python virtual environment, You can issue anyone command according to your operating system.
After activating Python’s virtual environment your terminal will look something like this.
(venv) D:\Django Projects>
After successfully creating and activating Python virtual environment you have to install Django first. The issue below command to install the latest version of Django.
pip install django
The above command will install the latest version of Django in your separate Python virtual environment.
Create Django Project
To create the first Django project you have to use the below command.
django-admin startproject myproject
After executing the above command, It will create a Django project. Here myproject represents the name of the project.
Your project structure will look something like this.
Let’s see a quick overview of all these folders and files.
manage.py:- This is a python .py file that is a very useful file. Basically, it is a command-line utility that is similar to the django-admin command-line utility. Python manage.py allows us to interact with Django projects in various ways.
In a later article, we will see all the manage.py commands.
db.sqlite3:- This is a sqlite3 database.Sqlite3 is a serverless file-based database with zero configuration.
myproject:- It is a directory or Python package that contains the following files.
- asgi.py:- It is an asgi file where asgi means Asynchronous Server Gateway Interface that increase the functionality of Web Server Gateway Interface.
- settings.py:- It is important to file all the Django projects because it contains all the important settings and configurations of the Django project.
- urls.py:- This file contains all project URLs or routes.
- wsgi.py:- This file is mostly used during the deployment of the Django project. It is a calling convention for a web server to forward requests to the web application.
Run Django Server
After successfully doing all the above steps, we have to up our Django project. One of the greatest things about Django is that it provides a development server that runs on our local machine.
To run the Django development server, issue the below command.
python manage.py runserver
When the above command will run successfully, you have to visit http://127.0.0.1:8000/ address to see the Django application user interface.
I know it’s not a fancy user interface because we haven’t worked on any real-life project, we just built our first Django application it’s a simple user interface that comes with Django by default. In later Django articles, we’ll try to design a fancy user interface.
So, in this article, we have seen how to create the first Django project. I hope that after this article, you will not have any confusion about how to create the first Django project.
If you like this article, please share and keep visiting for further Django tutorials because all the upcoming Django tutorials will be very interesting.
Thanks for your valuable time …