10 C
Texas
angeloma
Senior Writer and partner

How to install Django on CentOS 8?

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.

- Advertisement -

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.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article