How to Install Django on Ubuntu 20.04. Don’t you think having a flexible framework will make your task easier while developing the applications? Of course yes. Using a flexible framework will help you to automate the implementation, reduce task complexity, a time consuming, and most important complete focus on application logic. In that case, today we are going to explain one of the popular Python frameworks that are known as “DJANGO” and also known as model-template-view. Let’s know fundamental concepts that come under the Django framework.
What is Django?
Django is a python based full stack framework. This framework works based on the model-template-view architectural patterns. Django is considered to be one of the popular web based development frameworks for developing Python’s server applications. Now it is listed as one of the 10 web based development python frameworks of 2020. Django works based on Don’t Repeat Yourself principles. It is a free to use and open source python Full stack framework. It is the most widely used high level framework that enables developers to develop secure and maintainable websites. The main purpose to use Django is to avoid any commonly occurring security mistakes and also protect the websites automatically.
Django server has been increasing its popularity with the help of mechanisms like counting the number of Github projects and stack overflow questions for each tool or platform. The high profile websites that use Django are Disqus, Instagram, MacArthur Foundation, National Geographic channel, Knight Foundation, Pinterest, Open knowledge foundation, and open stack software. In recent times Django is a thriving and collaborative open source project that has been used by contributors and developers.
In the intro section only we have explained why the Django framework is a popular and widely used platform among others. Now it’s time to know about the salient features of Django:
1. It is a popular python web framework: as we already know that Django is built using python language. Python is robust in nature with the features like easy to learn and open source language. Especially this feature makes Django a great choice for web development.
2. High scalability: Scalability grows as the application requirement increases. Many top companies prefer to have a Django framework in the web development they are; Instagram, YouTube, Pinterest, Spotify, Quora, and Stack overflow. The number of Django application users has been increasing day by day and it is a complete full stack application development framework.
3. Exceptionally secure application: Django is a highly secured framework because it successfully covers the loopholes of web developments, helps developers to avoid any mistakes, and is also a secure way to manage accounts.
4. Thoroughly tested: Django is a durable framework and powerful enough to withstand the dynamic modifications that any application development requires. Moreover, the Django community supports fully tested features that make Django a bug free framework.
5. Fast development: one plus point of using Django is that it is a combination of both frontend and backend applications that offers a complete package of functional websites. While working with Django the developers no need to separate server files to design the database and connect with different database servers. So we dont need the extra files to handle plenty of tasks.
6. Active community support: Django online community and experts help the developers to reduce the web application development cost and complexity. Most of the Django communities have been working non stop to help developers to resolve any issues.
7. Support model-view-template architectural patterns: Django not only supports large size enterprises but also supports mid level and small size enterprises because of the MVT (model view pattern) architecture pattern. The MVT pattern in Django also helps developers to build complex websites keeping business logic and user interface in mind.
In this post, we will show you how to install Django on Ubuntu 20.04
By default, Python 3 comes pre installed on Ubuntu 20.04. However, it is available as a python3, not python. So you will need to create a symbolic link of the Python3 binary from /usr/bin/python3 to /usr/bin/python. You can create it by running the following command:
There are several ways to install the Python Django Framework on Ubuntu 20.04 server. In this section, we will explain each method to install Django on Ubuntu 20.04.
Install Django Using APT
By default, Django version 2.2.12 is available in the Ubuntu 20.04 default repository. You can install it by just running the following command:
apt-get install python3-django -y
After installing the Django Framework, verify the Django version with the following command:
django-admin --version
You will get the following output:
2.2.12
Install Django Using PIP
You can also use the PIP command to install Django via the PyPI repository. This method allows you to install the specific version of Django for your project.
To install the Django version 3.0.0, run the following command:
pip install django==3.0.0
After the successful installation, verify the Django version with the following command:
django-admin --version
You will get the following output:
3.0
Install Django Using Virtualenv
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:
pip install virtualenv
After the installation, create a new Python virtual environment named venv using the following command:
virtualenv venv
Next, change the directory to venv and activate the virtual environment with the following command:
cd venv/
source bin/activate
Next, install the Django version 3.0.0 using the following command:
Next, install the downloaded Django using the following command:
pip install -e django-dev
Once Django is installed, verify the Django version with the following command:
django-admin --version
You will get the following output:
4.1.dev20220218123749
Create a Django Project
In this section, we will show you how to create and run a Django project. First, create a new virtual environment named project with the following command:
virtualenv project
Next, change the directory to the project and activate it with the following command:
cd project
source bin/activate
Next, install the Django version 3.0.0 using the following command:
pip install django==3.0.0
Next, create a new Django project named djangosite with the following command:
django-admin startproject djangosite
Next, change the directory to djangosite and edit the settings.py file:
cd djangosite
nano djangosite/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:
python manage.py migrate
Next, create a superuser to log into the Django admin interface:
python manage.py createsuperuser
Provide your admin username, password, and email as shown below:
Username (leave blank to use 'root'): admin
Email address: admin@example.com
Password:
Password (again):
Superuser created successfully.
Next, start the Django project with the following command:
python 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 19, 2022 - 04:42:42
Django version 3.0, using settings 'djangosite.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:
In this post, we explained four methods to install Django on Ubuntu 20.04. You can now use your preferred method to install Django on Ubuntu 20.04. For more information, visit the Django documentation page.
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.