How to Install Django on CentOS 8

Install Django on CentOS 8

In this article, we will have explained the necessary steps to install and configure Django on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Django is a high-level Python Web framework that is free, open-source, and rapid development. It provides higher security for the application and avoids developers from making common security mistakes. By using Django you can build secure, scalable, and maintainable dynamic web applications.

Install Django on CentOS 8

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo dnf clean all
sudo dnf update

Step 2. Install Python and Pip on CentOS.

Run the following to install Python and Pip:

sudo dnf install python36 python3-pip

Now check the installed version of Pip with the following command:

$ pip3 -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6) 8

Step 3. Install Django on the CentOS system.

Now proceed and install Django web framework using the command:

sudo pip3 install Django

Verify the installation using the following command which will print the Django version:

$ django-admin --version
3.0.2

Step 4. Creating a Django project.

The next step is to start a new Django project:

sudo django-admin startproject linuxtips

Next, navigate into the linuxtips folder and migrate to set the initial configuration:

cd linuxtips 
sudo python3 manage.py migrate

Then, you have to create the superuser to manage the project:

sudo python3 manage.py createsuperuser

The next step is to edit the project configuration file to make it accessible from any computer:

nano example/settings.p

And edit the following entry:

ALLOWED_HOSTS = ['YOUR_COMPUTER_IP_ADDRESS_WHICH_IS_RUNNING_DJANGO']

### EXAMPLE ###

ALLOWED_HOSTS = ['192.168.77.20']

Then, serve the project:

sudo python3 manage.py runserver 0.0.0.0:8000

Step 5. Configure Firewall.

We need to allow port 8000, which the default port that our application will be listening to. Proceed and open the port on firewalld as shown:

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

Step 6. Accessing the Django Web App

Once installation and create project done, open http://192.168.77.20:8000 in your web browser and you will be presented with the default Django landing page:

Install Django on CentOS 8

Congratulation, you have learned how to install and configure Django on CentOS 8. For further reading on Django, please refer to their official knowledge base. If you have any questions, please leave a comment below.