In a world where the premise is that time is money, you need tools that allow you to develop applications or faster. The Frameworks exist to save you from having to reinvent the wheel and help you ease the burden when you build a site.
Django is an open source web development framework, written in Python, that respects the design pattern known as Model-view-template. Developed by experienced programmers, Django handles much of the complexity of web development, so you can concentrate on writing your application without reinventing the wheel.
Django is now a thriving open source collaborative project, with thousands of users and contributors. While it still has some features that reflect its origin, Django has evolved into a versatile framework that is capable of developing any type of website.
Django: a versatile framework
Apart from the main features that should be used in almost all web applications: URL mapping, views, templates and templates, Django also provides:
- Forms: Django simplifies the creation, validation and processing of forms.
- User authentication and permissions: Django includes a robust authentication and permissions system
- Data Serialization: Django makes it easy to serialize and serve your data as XML or JSON.
- An extensible template system based on labels, with template inheritance.
- Internationalization support, including built-in translations of the administration interface.
And of course many more things.
Let’s go for it. Installing Apache web server
We will see how to install Django in CentOS, and we have several ways to do it, we will use pip for it because it guarantees us flexibility and having the latest stable version of the framework.
For this tutorial we must have root access. To have it we must write:
         sudo -i
Obviously if we are going to install Django, it is because we must have a web server running, together with the database manager.
Installing the apache web server can be done with the command:
          yum install httpd
Once installed, we must initialize the service and enable it so that when starting the system, it also initializes:
         systemctl start httpd.service
         systemctl enabled httpd.service
It is a good idea to go to your web browser and verify that the web server is running correctly:
           http://ip_server
If we see the image above, it means that the web server is running and there are no problems so far, that is, we can continue.
Installing MariaDB
MariaDB is one of the most reliable and secure open source database managers available. It stands out for its robustness, ease of use and extensive existing documentation. We must install it:
         yum install mariadb mariadb-server
And then, we must start the service and enable it to run at system startup.
          systemctl start mariadb.service
          systemctl enable mariadb.service
Then we’ll invoke the mysql script to quickly configure mariadb. We’ll answer the questions like this: Y,Y,N,Y,Y.
            mysql_secure_installation
And now we log in to mariadb to execute a statement and test the installation we just did.
           mysql -u root -p
After entering the root password, we will be in the mariadb console. We’ll write on it:
          SHOW DATABASES;
By showing us the created databases we confirm the success of the process.
It’s Django’s turn
CentOS does not provide, by default, some packages we need, so we will add the EPEL repository. EPEL is open source and free community based repository project from Fedora team which provides 100% high quality add-on software packages for CentOS, Red Hat Linux and others:
          wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
And then:
         rpm -ivh epel-release-latest-7.noarch.rpm
We check if the repository was added correctly:
          yum repolist
As we see in the image, the EPEL repository was added and is part of the system’s software sources.
Now we proceed to install python-pip that will allow us to install Django.
          yum install python-pip
Now we can install Django with the command:
           pip install django
That command will install pip, but we need to update it to be compatible with the updated version of Django. That’s why we’re writing:
           python -m pip install –upgrade pip setuptools
And now, yes, we proceed to install it:
         python -m pip install django
We check which version is installed:
         django-admin –version
The installed version is LTS which guarantees stability and security updates for a long time.
Creating a simple project in Django
To create a simple Django project we can do it with the following command:
          django-admin startproject test1
And now we access the folder:
         cd test1
Then we start the database configuration instructions with the following command:
          python manage.py migrate
The next step is to create an administrative user to manage the project:
         python manage.py createsuperuser
You will ask us for information such as username, email and password (it should not be too short):
Now we must modify the options file to define the hosts allowed to manage the project.
         cd test1
         nano manage.py
And in it we must modify the host by the ip address of our computer. Once modified, press crt + x and say yes
Now head back to the parent directory with the command below:
          cd ../
And we run the framework as such. Don’t forget to replace the ip I put in with yours.:
        python manage.py runserver 192.168.250.4:8000
Now with the server running, we proceed to go to our web browser and place the ip of the web server and the port selected for Django.
Unlocking the port on CentOS
It is possible that even if you do these steps, you may still get an error when accessing from your browser. The port probably needs to be opened in the CentOS firewall.
To do this, we must enter the following commands:
          firewall-cmd –zone=public –add-port=8000/tcp –permanent
          firewall-cmd –reload
Django is a powerful framework for web technologies, flexible, free and with a large community behind its development, intended for perfectionist web developers.
Its installation is not complex but it requires several steps for its operation. All that’s left now is to start coding.
Please share this article through your social networks.