INSTALL DJANGO FRAMEWORK ON LINUX
Django is a Python framework that makes it easier to create web sites using Python.
Django takes care of the difficult stuff so that you can concentrate on building your web
applications. Django emphasizes reusability of components, also referred to as DRY (Don't
Repeat Yourself), and comes with ready-to-use features like login system, database
connection and CRUD operations (Create Read Update Delete).
How does Django Work?
Django follows the MVT design pattern (Model View Template).
Model - The data you want to present, usually data from a database.
View - A request handler that returns the relevant template and content - based on the
request from the user.
Template - A text file (like an HTML file) containing the layout of the web page, with
logic on how to display the data.
Model
The model provides data from the database. In Django, the data is delivered as an
Object Relational Mapping (ORM), which is a technique designed to make it easier to work
with databases. The most common way to extract data from a database is SQL. One problem
with SQL is that you have to have a pretty good understanding of the database structure to be
able to work with it. Django, with ORM, makes it easier to communicate with the database,
without having to write complex SQL statements. The models are usually located in a file
called [Link].
View
A view is a function or method that takes http requests as arguments, imports the
relevant model(s), and finds out what data to send to the template, and returns the final result.
The views are usually located in a file called [Link].
Template
A template is a file where you describe how the result should be represented.
Templates are often .html files, with HTML code describing the layout of a web page, but it
can also be in other file formats to present other results, but we will concentrate on .html files.
Django uses standard HTML to describe the layout, but uses Django tags to add logic:
Instalation
Installing Django on Linux typically involves these steps: Ensure Python and pip are
installed. Django is a Python web framework, so Python needs to be installed. pip is the
package installer for Python and is used to install Django. You can check if they are installed
by opening a terminal and running:
python3 --version
pip3 –version
If they are not installed, you can usually install them using your distribution's package
manager (e.g., sudo apt install python3 python3-pip on Ubuntu/Debian, or sudo dnf
install python3 python3-pip on Fedora/RHEL). Create a virtual environment
(recommended).
Virtual environments help isolate project dependencies, preventing conflicts between different
Django projects or other Python applications.
python3 -m venv myprojectenv
Activate the virtual environment:
source myprojectenv/bin/activate
(The prompt in your terminal will likely change to indicate the active virtual environment.)
install django. With the virtual environment activated, install Django using pip:
pip install Django
To install a specific version, you can specify it:
Code
install Django==5.2.7
verify the installation.
You can check the installed Django version to confirm the installation:
python -m django –version
Alternatively, you can open a Python interpreter within the activated virtual environment and
try importing Django:
import django
print(django.get_version())