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
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
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
Now you need to create the Django console administrator user. We achieve this with the following command:
:~# python3 manage.py createsuperuser
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']
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:
If you want to access the administration panel, add to the previous address /admin
.
Just type your credentials and you will see the 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.