How to install Django on CentOS 8?

Windows Articles

How to get the Nextcloud desktop client on Linux?

Hello friends. We already know how to install a Nextcloud server but now the client is missing. So in this post, you...

How to Backup your call and SMS history in Android

Many times we find ourselves in the situation of having to change our phone, for different reasons, and one of the questions...

Install and configure Apache Guacamole on Debian 10

Hello, friends in this post, you will learn how to install and configure Apache Guacamole in Debian 10. It will be a...

Ubuntu 20.10 available

The new version of Ubuntu is now available, under the code name "groovy gorilla". Ubuntu 20.10 focuses on improving and refining the...

Monitoring Ubuntu 20.04 with Stacer

Normally if we use Linux on a production server, it is important to monitor it. On the other hand, in everyday use, many users...
angeloma
angeloma
Senior Writer and partner

Developing web applications is usually related to PHP frameworks. However, Python, which is a very versatile programming language, also has a framework that allows you to do it. And in fact, it is quite efficient. So, if you like Python and you think it is convenient to develop web applications with this language, then you should know Django. In this post, you will learn how to install Django on CentOS 8.

Briefly, What is Django?

The Django is a framework written in python to develop web applications. It respects the design pattern Model – View -Template and focuses on making applications quickly and under the focus of DRY (Don’t repeat yourself).

It is incredibly popular and great websites are created with this Framework. So, let’s go for it.

Install Django on CentOS 8

1.- Install Python and Pip on CentOS 8

Django is a framework built-in Python. That’s why you have to have it in your system. However, don’t worry that most Linux distributions are installed by default.

Different from python, Pip is not installed by default. And it is another necessary package for Django. So, we have to install it.

Open a terminal session and run the following:

:~$ su
:~# dnf install python36 python3-pip
1.- Install Python pip on CentOS 8
1.- Install Python pip on CentOS 8

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)

With this, Python and Pip are ready to continue the work.

Install Django on CentOS 8

Now we proceed to install Django with the following command.

:~# pip3 install Django
2.- Install Django on CentOS 8
2.- Install Django on CentOS 8

Then, check the version that has been installed:

:~# django-admin --version
3.0.2

Remember that the version will change according to when you do this tutorial.

The next step is to start a new Django project. Just use the following command:

:~# django-admin startproject example

Replace example with the name you wish to give the project.

Then navigate to the created folder, in this case, example, and make the migrations.

:~# cd example
:~# python3 manage.py migrate
3.- Installing Django on CentOS 8
3.- Installing Django on CentOS 8

Now you need to create the Django console administrator user. We achieve this with the following command:

:~# python3 manage.py createsuperuser
4.- Creating the user for Django
4.- Creating the user for Django

As you see in the picture, we will be asked for a username. Then, we define a password.

When you finish creating the user, you have to change a value in the Django configuration. To do so, open the settings file with the following command:

:~# nano example/settings.py

And modify the following parameter:

ALLOWED_HOSTS = ['COMPUTER_IP_WHICH_IS_RUNNING_DJANGO']
5.- Configuring Django on CentOS 8
5.- Configuring Django on CentOS 8

Then save the changes and close the editor.

Django applications are served through the 8000 port. Therefore, it’s necessary to open this port in the firewall so that we can access it.

:~#firewall-cmd --add-port=8000/tcp --zone=public --permanent
 success
:~# firewall-cmd --reload
 success

Now open your web browser and go to http://localhost:8000 or http://pc-ip:8000 and you will see this:

7.- Django running on CentOS 8
7.- Django running on CentOS 8

If you want to access the administration panel, add to the previous address /admin.

8.- Django log in page
8.- Django log in page

Just type your credentials and you will see the dashboard.

9.- Django dashboard
9.- Django dashboard

So, Django is installed and ready to work.

Conclusion

Django is a powerful framework. It combines the simplicity of python with the power of a whole team willing to improve the framework. Besides this, the installation on CentOS 8 is not complicated at all.

Please share this post and join our Telegram Channel.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to get the Nextcloud desktop client on Linux?

Hello friends. We already know how to install a Nextcloud server but now the client is missing. So in this post, you...

How to Backup your call and SMS history in Android

Many times we find ourselves in the situation of having to change our phone, for different reasons, and one of the questions...

Install and configure Apache Guacamole on Debian 10

Hello, friends in this post, you will learn how to install and configure Apache Guacamole in Debian 10. It will be a...

Ubuntu 20.10 available

The new version of Ubuntu is now available, under the code name "groovy gorilla". Ubuntu 20.10 focuses on improving and refining the...

Monitoring Ubuntu 20.04 with Stacer

Normally if we use Linux on a production server, it is important to monitor it. On the other hand, in everyday use, many users...
x