Django is a free and open-source web framework written in the python programming language. It follows the model-template-views architectural pattern and allows rapid development. Django is versatile in nature that can be used to create applications in multiple domains. It takes less time to develop a web application than other web frameworks.
This article will explain how to install and use Django on CentOS.
- A root or non-root user with
- We need to set up Python and Pip on CentOS.
Install EPEL Repository
All the below installation methods are based on the EPEL library for CentOS need to enable the EPEL repository before installation of python Django on CentOS.
- To configure the EPEL library, run the below command.
# sudo yum -y install epel-release
- It is recommended by the Django Software Foundation to use Python 3, Run the below command to install Python 3.
# sudo yum install -y python3
- Check which version of Python you have installed.
$ python3 -VOutput:
- Need pip in order to install packages from PyPi, Python’s package repository, to install pip follow the below command.
# sudo yum install -y python3-pip
- Install Python Django on CentOS by using the below command.
# sudo pip3 install django==2.1.*
- Check which version of Django you have installed.
# django-admin --version
- Run the following command to create the new project. This command creates a new directory called "project_name".
# django-admin startproject project_name
- Run the below command to create an application for the project.
# python3 project_name/manage.py startapp app_name
- Migrate the project database.
python3 project_name/manage.py migrate
setting.pyfile using the below command.
# sudo vi project_name/project_name/settings.py
ALLOWED_HOSTSinside the file and list your serve IP addresses or domain names in the ALLOW_HOSTS then save and close the file.
- Start the Django development server.
Replace your IP address with <your_server_ip> in the above command.
# python3 project_name/manage.py runserver your_server_ip:8000
- Open the web browser and visit your server IP address followed by:8000 port.