A web framework is a software library that is designed to support the development of web applications. There are many frameworks that have been developed including Ruby on Rails, Django, Laravel, ASP.NET, Angular, and Express. But in this guide, we will be looking at how to install and use Django KDE Neon / Kubuntu Linux system.

Django is a free, open-source high-level web framework based on Python. It was invented to meet the needs of experienced web developers by eliminating repetitive tasks which make the development process time-saving and easy. It generally reduces the hassle that comes with developing web applications.

Features of Django Framework

  • Ridiculously fast in development with less coding
  • Loosely coupled to reduce risks of data loss
  • Secure and helps developers to avoid security mistakes
  • Scalable and flexible to meet even the heaviest demands.
  • Clean design making it maintainable.
  • Complete and Fully Loaded with extras used to handle common web development tasks
  • Versatile in that it can be used to build different web applications

In this guide, I will show you how to

  • Install Django on KDE Neon
  • Create a Django application

Install Django Framework on KDE Neon / Kubuntu

To Install Django, You are required to set up python and pip in your system.

Setup Python and Pip on KDE Neon / Kubuntu

Update the package index first by running the following command:

sudo apt update 

If there are any upgrades required use the command the next command to upgrade the packages.

sudo apt upgrade

By default python is installed in the system, You can test this using python command

If not then install using 

sudo apt install python3

The installation is successful as shown below

To confirm the installation use 

$ python3 --version

The version is displayed as follows

Now install pip which is a package manager for python packages

sudo apt install python3-pip 

If prompted on disk space to be used, type Y to continue with the installation.

To check the version use the command:

pip3 --version

The version is displayed as follows

Install Django on KDE Neon/Kubuntu from the Repository

Now install Django using the commands shown below:

sudo apt install python3-django

This install from the repository as below

To check the installation was successful, use 

django-admin --version

It displays the version as below

Creating a Sample Project using Django

First, install Python virtual environment on your Kubuntu / KDE Neon system.

sudo apt install python3-virtualenv

If prompted with disk space type Y to continue with the installation

Then create a directory for your project using mkdir command:

mkdir django-app

Then change to that directory using

cd django-app

Next will be to create a new virtual environment.

$ virtualenv newproject
created virtual environment CPython3.8.10.final.0-64 in 159ms
  creator CPython3Posix(dest=/home/ubuntu/django-app/newproject, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/ubuntu/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

 Go to the newproject directory and activate the environment

cd newproject

Then install packages into the isolated environment using

source bin/activate

Now install Django using the pip command

$ pip3 install django
(newproject) [email protected]:~/django-app/newproject$ pip3 install django
Collecting django
  Downloading Django-4.0.3-py3-none-any.whl (8.0 MB)
     |████████████████████████████████| 8.0 MB 10.2 MB/s
Collecting asgiref<4,>=3.4.1
  Downloading asgiref-3.5.0-py3-none-any.whl (22 kB)
Collecting backports.zoneinfo; python_version < "3.9"
  Downloading backports.zoneinfo-0.2.1-cp38-cp38-manylinux1_x86_64.whl (74 kB)
     |████████████████████████████████| 74 kB 7.4 MB/s
Collecting sqlparse>=0.2.2
  Downloading sqlparse-0.4.2-py3-none-any.whl (42 kB)
     |████████████████████████████████| 42 kB 4.3 MB/s
Installing collected packages: asgiref, backports.zoneinfo, sqlparse, django
Successfully installed asgiref-3.5.0 backports.zoneinfo-0.2.1 django-4.0.3 sqlparse-0.4.2

The output is as follows

Now create a Django project named technixleo . You can replace the name with however you want to save the file.

django-admin startproject technixleo

Navigate to the new directory using:

cd technixleo

You can check the contents of the application by using tree

Now edit the configuration files inside settings.py

nano technixleo/settings.py

On the ‘ALLOWED_HOSTS’ configuration, input your System’s IP address as below.

ALLOWED_HOSTS = ['your-server-ip-address']

If you have more than one Ip address you want to access the Django server just separate them with a comma.

Next, we will migrate the database for our Django project.

Migrate the Django database using the following command.

$ python3 manage.py migrate
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 auth.0012_alter_user_first_name_max_length... OK
  Applying sessions.0001_initial... OK

By default, the Django framework uses the SQLite database.

After that, create a new admin user for your Django project.

python3 manage.py createsuperuser

Now type your username, email address, and password, then press enter.

Note: use a strong password and not be like me 🙂

Run Django Application

Run the Python Django runserver command below.

python3 manage.py runserver 0.0.0.0:8000

The server starts running as shown below

Open your browser and access the Django application with your server IP and port 8000

http://your_server_ip:8000

You can get your System IP address by using ip a command.

Add admin to the end of the address to log in to the admin dashboard.

http://your_server_ip:8000/admin/

Enter your credentials to log in to the administration dashboard. This allows you to create users and groups.

Conclusion

You have learned how to set up Python and Pip in your system which in turn led to installing Django from the repository. You also learned how to create a Django application in an isolated environment. You also learned how to run the Django application on a web browser which in turn shows the installation is successful.

More guides in our website:

LEAVE A REPLY

Please enter your comment!
Please enter your name here