Django is a free and open-source web framework, written in Python. It's primary goal is to ease the creation of complex, database-driven websites.Django also provides an optional administrative create, read, update and delete interface that is generated dynamically through introspection and configured via admin models.
It consists of:
- An object-relational mapper (ORM)
- A relational database ("Model")
- A system for processing HTTP requests("View")
- A regular-expression-based URL dispatcher ("Controller")
Install EPEL repository
As we are going to install some Python packages, we need to have EPEL installed because some of them are not provided by the official repository:
yum install epel-release
Global installation through pip
If you want to install the latest version of Django you can install it with the following command, First, we need to install the pip (Python’s package manager).
yum install python-pip
Once you have pip installed you can install Django easily with the command below:
pip install django
you can check the version of you installed Django with the command below, it also verifies that the installation process was successful.
Create a simple project in Django
Now that you have Django installed, we can go ahead and find out how to start a project in Django framework.
You can use the “django-admin” command to create a project (make sure to replace the red parts with your own preferred values):
django-admin startproject hugeserver
You created a project named “hugeserver“, switch to it with the following command:
Execute the following command in order to get the initial database instructions:
python manage.py migrate
Now you have to create an administrative user for your project with the command below:
python manage.py createsuperuser
- Username (leave blank to use ‘root’): type your username then hit enter.
- Email address: set the primary Email address.
- Password: Enter a password at least 8 characters.
- Password (again): confirm your password
If you have done everything right you get the following output:
Superuser created successfully.
Before we can start our Django project we have to define Allowed user in the Django setting.
Switch to the root directory of your project with the command below (the directory has the name same as your project):
Open the setting file with your text editor:
Find the line that refers to “ALLOWED_HOSTS = ”
and put your public IP address within the brackets just like below:
ALLOWED_HOSTS = ['*']
This way you can run your Django on any port you want.
Now head back to the parent directory with the command below:
And run your Django framework with the command below:
python manage.py runserver 0.0.0.0:8000
This will start your Django on port 8000 and make it accessible through your public IP address or your Domain. you can visit it at the following URL: