In this article about how to Install Django on CentOS 8, we will also introduce Django and its features.Â
What is Django Server?
Django is a Python based open source framework used by most developers to build or write custom web applications. Its simple syntax rule helps keep the code base clear and readable so making it easier for developers to design and maintain web applications. Django was released in 2003 by Adrian Holovaty and Simon Willison, comprising in built features that aid in a faster web development process.
The web framework further allows developers to build complex database driven websites with less coding. It has a ready to use user interface and supports various formats such as JSON, HTML, XML, etc. Another feature of Django is the batteries included web framework. This feature enables developers to build websites as per different business requirements.
Django server supports many relational database systems and helps build multilingual websites with its in built internationalization system. It supports various other features like predefined libraries, an integrated unit testing system, dynamic HTML pages for web framework.
The open source web framework is easy to learn and allows programmers to design custom web applications without any hassle. Below are a few additional benefits of using the Django web framework.
Written in Python:Python is one of the popular programming languages, easy to learn and implement. As the Django web framework is Python based, it gets easier for developers to build web applications and maintain code. Also, the programmers can save time by reusing the code and eliminating the need for writing additional code when building custom web applications.
Advanced security features: It holds variety of built security features and authentication systems that protect web applications from attacks and threats. The Get Method is uses it transmits the information but keeps all the passwords and security information encrypted. SQL injection, cross site scripting, and cross site request forgery are the built in features that aid the information to always stay protected.
Compatible with most operating systems and databases: People access web applications on different devices and platforms. Django ensures that the built web applications support various operating systems like Windows, Linux, macOS, etc., and are easily accessible to users. Also, the ORM system by Django ensures that the developers can work with most databases, including MySQL, Oracle, etc. You can use the system to transfer information and perform database operations without extra code required.
Large and active community support: Being a Python based framework, Django aids in reducing development costs and it is supported by a large and active developers community where there are frequent share updates related to new plugins or code snippets to simplify the development process. Using these resources and information, the programmers can speed up their process and resolve issues.
Batteries Included Framework: Django follows the batteries included approach when designing a custom web application. It uses the out of the box resources and reuses the code to save time. To perform operations, such as database manipulation, URL routing, session management and HTML templating, the framework provides codes and helps save the web application development time by reusing them.Â
Easy to Extend and Scale: The framework allows developers to build large and complex web applications by making a few changes to the separated components of the web applications. It aids in customizing, scaling and extending the web framework easily. In addition the programmers can unplug or replace these decoupled components as per their project requirements.
Fast Processing: Django’s MVC (Model View Controller) core architecture helps in faster processing as it allows to put resources on a CDN while maintaining the speed.
Django provides a dynamic CRUD (create, read, update and delete) interface, configured with admin models that aids in speedy process.
Other features are:
An emailing system to send notifications to users.
High load booking engines perfect for shopping platforms.
In the next section we will show you how to install Django on CentOS 8.
You can also install Django in Python virtual environment. Python Virtualenv allows you to create isolated python environments for your project. It is very useful because it allows developers to run and develop an application with different python versions.
First, install the Python virtualenv package using the following command:
pip3 install virtualenv
After the installation, create a new Python virtual environment named newenv using the following command:
Next, change the directory to the django and activate it with the following command:
cd django
source bin/activate
Next, install the Django version 3.0.0 using the following command:
pip3 install django==3.0.0
You should see the following output:
Using cached Django-3.0-py3-none-any.whl (7.4 MB)
Collecting sqlparse>=0.2.2
Using cached sqlparse-0.4.2-py3-none-any.whl (42 kB)
Collecting asgiref~=3.2
Using cached asgiref-3.4.1-py3-none-any.whl (25 kB)
Collecting pytz
Using cached pytz-2021.3-py2.py3-none-any.whl (503 kB)
Collecting typing-extensions
Using cached typing_extensions-4.1.1-py3-none-any.whl (26 kB)
Installing collected packages: typing-extensions, sqlparse, pytz, asgiref, django
Successfully installed asgiref-3.4.1 django-3.0 pytz-2021.3 sqlparse-0.4.2 typing-extensions-4.1.1
Next, create a new Django project named examplesite with the following command:
django-admin startproject examplesite
Next, change the directory to examplesite and edit the settings.py file:
cd examplesite
nano examplesite/settings.py
Add your server IP address in the ALLOWED_HOSTS:
ALLOWED_HOSTS = ["your-server-ip"]
Save and close the file, then migrate the Django database with the following command:
python3 manage.py migrate
You will get the following output:
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying sessions.0001_initial... OK
Next, create a superuser to log into the Django admin interface:
python3 manage.py createsuperuser
Provide your admin username, password, and email as shown below:
Username (leave blank to use 'root'): djangoadmin
Email address: admin@example.com
Password:
Password (again):
Superuser created successfully.
Next, start the Django project with the following command:
python3 manage.py runserver 0.0.0.0:8080
You will get the following output:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 24, 2022 - 13:57:11
Django version 3.0, using settings 'examplesite.settings'
Starting development server at http://0.0.0.0:8080/
Quit the server with CONTROL-C.
Now, open your web browser and access the Django home page using the URL http://your-server-ip. You should see the Django home page in the following screen:
To access the Django admin interface, type the URL http://your-server-ip/admin. You will be redirected to the Django login page:
Provide your admin username, password, and click on the Log in button. You should see the Django dashboard on the following screen:
This post explained how to install Django on CentoS 8.We have explained what Django framework is, what it is for, and where it is used. Django is a great addition to projects that need to handle large volumes of content as well as user interactions. it is also beneficial for projects with handling heavy traffic or to deal with complex functions or technology (e.g., machine learning).
Â
Django is simple enough to be also used for smaller scale projects or for project you intending to scale up. Django is great at building a fast website. You can now choose your preferred method to install Django on CentOS 8.Â
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.