Table of contents
Django is one of the best web frameworks written in python. It enables to build the full-scale web application efficiently as it contains many libraries and tools that handle many tasks like URL routing, authentication, database management, and more in an easy way.
Let's see how to set up and run your first Django project.
Steps to be followed
By using the terminal create a folder
myproject
and enter into it.mkdir myproject cd myproject
Create a virtual environment and activate it in the entered folder. So that you can later install the dependencies required for the project in the virtual environment so that the main environment will not get affected.
python -m venv env env\Scripts\activate
Install the Django package in the virtual environment through package manager pip.
pip install django-admin
Create a Django project called
project
django-admin startproject project
Now Django will create
project
folder in which you will find the Django project calledproject
and the required files.The file structure should be like this.
If you don't want your Django project in a separate folder called
project
but instead in the root foldermyproject
, you should execute the below command while creating the Django projectdjango-admin startproject project .
Now the file structure should be like this.
Now that you have set up the Django project, to run it on a web browser execute the command
python manage.py runserver
Open the web browser and go to the URL shown in the terminal (usually it will be http://127.0.0.1:8000/ )
Ta-da!, now your Django project is running in the web browser.
Conclusion
This is how you set up a Django project and run it on the server.
Thanks for reading the article. If you have any doubts regarding this feel free to comment below.