31.8 C
Texas
angeloma
Senior Writer and partner

Install Django on Debian 11

Hello friends. If you are fond of Python but also web development then you have to try Django. This powerful Python-based framework will allow you to develop robust web applications quickly and easily. So, in this post, you will learn how to install Django on Debian 11.

Introducing to Django

Django is an open-source framework written in Python and based on the MTV (Model Template View) design pattern for developing websites, applications, and APIs (with Django REST Framework).

Django was designed to help us develop applications from concept to completion as quickly as possible. It also takes security seriously and helps us avoid many common security bugs.

Moreover, Django’s ability to scale quickly and flexibly is one of its main advantages. So if you have a website such as a forum that you are going to add features to later, Django is a good alternative.

- Advertisement -

In addition, Django is incredibly versatile and can be used to build everything from content management systems to social networks and scientific computing platforms.

So, let’s get started.

Install Django on Debian 11

Before getting started with Django, it’s necessary to update the distribution so that we can avoid problems.

sudo apt update
sudo apt upgrade

Now we need to install PIP. This tool will help us with the installation of Django on our system.

sudo apt install python3-pip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  python-pip-whl python3-wheel
Recommended packages:
  build-essential python3-dev
The following NEW packages will be installed:
  python-pip-whl python3-pip python3-wheel
0 upgraded, 3 newly installed, 0 to remove and 3 not upgraded.
Need to get 2,309 kB of archives.
After this operation, 3,671 kB of additional disk space will be used.
Do you want to continue? [Y/n]

Next, we have to update PIP to the latest stable version available.

pip3 install -U pip
Requirement already satisfied: pip in /usr/lib/python3/dist-packages (20.3.4)
Collecting pip
  Downloading pip-21.2.4-py3-none-any.whl (1.6 MB)
     |████████████████████████████████| 1.6 MB 7.6 MB/s
Installing collected packages: pip
Successfully installed pip-21.2.4

Now check the installed version by running the following command

pip3 --version
pip 21.2.4 from /home/angelo/.local/lib/python3.9/site-packages/pip (python 3.9

Now you can install Django on your system with the help of PIP.

sudo pip3 install Django
Installing collected packages: sqlparse, pytz, asgiref, Django
Successfully installed Django-3.2.7 asgiref-3.4.1 pytz-2021.3 sqlparse-0.4.2

When you install Django, it will enable the django-admin command that we will use to administer Django. For now, check the installed version.

django-admin --version
3.2.7

Testing Django on Debian 11

Now we need to test the installation of Django and for that, we’re going to create a new project

Create a new folder dedicated to the project and go to it

mkdir example
cd example

You can replace example with any name you want. Now create the new project.

django-admin startproject project

Replace project with the name you will give to your project.

This will create a folder with the same name that you need to access.

cd project

Now you need to apply the default settings

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
.
.
.

Next, it’s time to create an admin user for Django.

python3 manage.py createsuperuser
Username (leave blank to use 'angelo'):
Email address: [email protected]
Password:
Password (again):
Superuser created successfully.

There you will be asked for a username and password to use.

Now you have to configure Django to allow remote access.

nano project/settings.py
ALLOWED_HOSTS = ['IP_PC']]

Save your changes and close the editor.

python3 manage.py runserver 0.0.0.0.0:8080
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 02, 2021 - 14:45:55
Django version 3.2.7, using settings 'project.settings'
Starting development server at http://0.0.0.0:8080/
Quit the server with CONTROL-C.

Now open your web browser and go to http://your-pc:8080 and you will see the main Django screen.

1.- Django site running
1.- Django site running

Then, to access the admin panel, go to http://your-pc:8080/admin.

2.- Django login page
2.- Django login page

After logging in you will see the dashboard.

3.- Django admin panel
3.- Django admin panel

So, enjoy it.

Conclusion

So, Installing Django on our system can help us if we are starting in this world of Python and the web. This process is made easy thanks to tools like PIP.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article