In this tutorial we are going to see how to set up the Django framework on Ubuntu. But before installing the Django we will see the quick introduction about the Django framework.
What is Django framework?
Django is a Python-based web framework. It is a free and open-source web framework that follows the model-template-views architectural pattern. It is maintained by the Django Software Foundation.
Now We see How to set up the Django on Ubuntu machine using python. There are two ways to setup flask on the Ubuntu machine
- Django Installation using the virtual environment
- Django Installation Without virtual environment
Django Installation Without virtual environment
Then benefit with ubuntu20.04 is, It comes with preinstall python3.6 version, so you need not struggle for setup python unlike the previous versions of Ubuntu. If you are using the old version of Ubuntu then you need to upgrade python version from python2.7 to python3.X
Step 1: First update your Ubuntu system using the following command
sudo apt update -y
Step 2: Install Django using pip command
pip3 install django
Step 3: To verify use the following command
django-admin --version
Django Installation Without virtual environment
It is always a good idea to setup Django with the virtual environment. So in this tutorial we are going to see How to setup the virtual environment and setup the Django inside it.
Step 1: First create a folder and enter to the folder using following command
mkdir DjangoProject && cd DjangoProject
mkdir – mkdir means make directory/folder
cd – cd means change directory/folder
in the above command we are executing two commands at a time first command is creating directory/folder by name DjangoProject and then entering that directory/folder.
Once we enter to this directory now we are ready for creating the virtual environment for our project.
What is a virtual environment?
Virtual environment is wrapper/folder around your project which holds all your project dependency and libraries related to your project.
Step 2: create a virtual environment using python3 command
python3 -m venv Djangoprojectven
command explanation:
python3 : we are creating virtual environment for python3
-m: -m means make
Venv: venv stand for virtual environment
Djangoprojectven: is the name of your virtual environment.
Step 3: Now you need to activate your virtual environment using following command
source Djangoprojectven/bin/activate
Once your virtual environment is activated it will show you (Djangoprojectven) at the beginning of your command
Step 4: Now you are ready to install django in virtual environment. Use the following command
pip3 install django
Step 5: To confirm that Django is installed, run:
django-admin --version
Now we will How to start the project
Step 6: user following command to start the project
django-admin startproject porjectName
Step 7: Now to run the project go inside the porjectName folder
Step 8: Now you will see the manage.py file. here execute the following command to run server.
Stpe 9: Now you will get ip address put it in browser and hit enter.
http://127.0.0.1:8000/
You will see your running project in the browser.
Thanks for reading !!! if you have any question please ask in a comment.