How to Install Django on CentOS 8

Django is a free and open-source, Python-based web framework that follows the model–template–views architectural pattern. It is maintained by the Django Software Foundation, an independent organization established in the US as a 501 non-profit.

Through this tutorial, we will learn how to install and configure Django on centOS 8.

How to Install Django on CentOS 8

Follow the following steps to install and use Django on CentOS 8:

  • Step 1 – Update System Packages
  • Step 2 – Install Python and Pip
  • Step 3 – Installing Django
  • Step 4 – Create a sample Django project
  • Step 5 – Configure Firewall
  • Step 6 – Accessing Django

Step 1 – Update System Packages

First of all, open terminal or command line and execute the following command into it to update centOS system packages:

sudo dnf update

Step 2 – Install Python and Pip

Once the system packages has been updated, then execute the following command on terminal or command line to install python and pip in CentOS:

sudo dnf install python36 python3-pip

Check the installed version of Pip:

pip3 -V

Step 3 – Installing Django

Execute the following command on the command line or terminal to install Django in CentOS:

pip3 install Django

Use the following command to verify the installation:

django-admin --version

Step 4 – Create a sample Django project

Currently that the Django framework has been installed. Now, using the following command on comman d line or terminal to create a sample project in django:

cd ~
django-admin startproject myproject

The command above will create a directory myproject in our working directory ~, and store all necessary files within.

Run the commands below in sequence to get your application started. Follow the instructions on the screen to provide the superuser’s credentials:

cd myproject/
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver 0.0.0.0:8000

Finally, use the “deactivate” command to leave your virtual environment:

deactivate

Step 5 – Configure Firewall

Execute the following command on command line or terinal to allow access to port 8000, for modify firewall rules in a new SSH connection:

firewall-cmd --add-port=8000/tcp --zone=public --permanent
firewall-cmd --reload

Step 6 – Accessing Django

Django will be available on HTTP port 8080 by default. Open favorite browser and navigate to

http://your-domain.com:8000 

OR

http://your-server-ip:8000/admin

Images mentioned above related to CentOS,Django are either copyright property of respective image owners.

Rabins Sharma Lamichhane

Rabins Sharma Lamichhane is senior ICT professional who talks about #it, #cloud, #servers, #software, and #innovation. Rabins is also the first initiator of Digital Nepal. Facebook: rabinsxp Instagram: rabinsxp

Leave a Reply

Your email address will not be published. Required fields are marked *