Page 2
What isDjango?
• Django is a high-level Python web framework
• Used to build websites and web applications
• Simplifies web development using Python
• Handles complex tasks automatically
• Allows developers to focus on application logic
3.
Page 3
Why UseDjango?
• Saves development time
• Follows DRY principle (Don’t Repeat Yourself)
• Built-in features:
oUser authentication
oDatabase connectivity
oCRUD operations
• Secure and scalable
• Widely used in industry
4.
Page 4
How DoesDjango Work?
• Django follows the MVT Architecture
• MVT stands for:
oModel
oView
oTemplate
• Separates data, logic, and presentation
• Improves code organization and maintenance
5.
Page 5
Django MVTArchitecture
• Model → Handles database and data logic
• View → Handles user requests and responses
• Template → Handles user interface (UI)
• Django internally manages the flow between them
6.
Page 6
Model (M)
•Represents data layer
• Interacts with the database
• Uses ORM (Object Relational Mapping)
• Eliminates need to write complex SQL
• Models are defined in models.py
7.
Page 7
Django ORM
•ORM maps database tables to Python objects
• Enables database operations using Python code
• Supports:
oInsert
oUpdate
oDelete
oRetrieve data
• Makes database handling easy and secure
8.
Page 8
View (V)
•HandlesHTTP requests
•Processes business logic
•Fetches data from models
•Sends data to templates
•Views are defined in views.py
9.
Page 9
Template (T)
•Defineshow data is displayed
•Usually written in HTML
•Uses Django Template Language (DTL)
•Supports variables and logic
•Stored inside templates folder
10.
Page 10
Template Example
<h1>MyHomepage</h1>
<p>My name is {{ firstname }}.</p>
• {{ firstname }} is a template variable
• Data comes from the view
• Logic and UI are separated
11.
Page 11
URLs inDjango
•Manages navigation between pages
•Maps URL patterns to views
•Each request is routed to a view
•URL configuration stored in urls.py
•Enables clean and readable URLs
Page 13
History ofDjango
•Developed by Lawrence Journal-World
•Created in 2003
•Designed for fast web development
•Released publicly in July 2005
•Built to meet tight deadlines
14.
Page 14
Django Versions
•Open-source framework
• Regular updates and improvements
• Latest version:
oDjango 4.0.3
oReleased in March 2022
• Supports modern web standards
15.
Page 15
Key Advantagesof Django
•Rapid development
•High security
•Built-in admin panel
•Scalable and flexible
•Strong community support
16.
Page 16
Django Requirements– Overview
•Django is a Python-based web framework
•To work with Django, we need:
oPython
oPIP (Python Package Manager)
oVirtual Environment
17.
Page 17
Django RequiresPython
•Django is written in Python
•Python must be installed before installing Django
•Django supports Python 3.x versions
18.
Page 18
Check PythonInstallation
•Open Command Prompt
•Run the command:
python --version
• If Python is installed, version will be displayed
• Example:
Python 3.13.2
19.
Page 19
What isPIP?
•PIP = Python Package Installer
•Used to install Python libraries and frameworks
•Required to install Django
•Included with Python from version 3.4 onwards
20.
Page 20
Check PIPInstallation
•Open Command Prompt
•Run the command:
opip --version
•pip –version
•If installed, version details will appear
•Example:
opip 24.3.1 (python 3.13)
21.
Page 21
Installing PIP(If Not Available)
• If PIP is not installed:
• Download it from:
https://pypi.org/project/pip/
• Follow installation instructions provided on the website
22.
Page 22
What isa Virtual Environment?
• A Virtual Environment is an isolated workspace
• Keeps project dependencies separate
• Prevents version conflicts between projects
• Recommended for every Django project
23.
Page 23
Why UseVirtual Environment in Django?
•Separate environment for each project
•Easy dependency management
•Cleaner and safer development
•Avoids system-wide package conflicts
24.
Page 24
Next Steps
•Createa virtual environment
•Activate the virtual environment
•Install Django inside the virtual environment
•Start building Django applications
25.
Page 25
Virtual Environmentin Django
• A Virtual Environment is an isolated workspace for a Python
project
• It keeps project dependencies separate
• Recommended to use one virtual environment per Django
project
• Helps avoid version conflicts
• Python provides built-in support using venv
26.
Page 26
Why UseVirtual Environment?
• Keeps project libraries isolated
• Avoids dependency conflicts
• Easy project management
• Safe environment for testing
• Required for professional Django development
27.
Page 27
Creating aVirtual Environment
• Python includes venv module
• Choose any name for the environment
• Example name used: myworld
• Command to create virtual environment:
python -m venv myworld
• Run this command in Command Prompt / Terminal
• Navigate to project folder before running
28.
Page 28
Virtual EnvironmentFolder Structure
After creation, a folder named myworld is created with:
• Include – Header files
• Lib – Installed Python packages
• Scripts – Activation files (Windows)
• pyvenv.cfg – Configuration file
• .gitignore – Git ignore settings
29.
Page 29
Activating VirtualEnvironment (Windows)
Activating Virtual Environment (Windows)
myworldScriptsactivate.bat
• Run inside project directory
• Activates the virtual environment
30.
Page 30
Activating VirtualEnvironment (Linux / macOS)
To activate on Windows:
myworldactivate.bat
• Run inside project directory
• Activates the virtual environment
31.
Page 31
Virtual EnvironmentActivated
Once activated, command prompt changes to:
Windows:
(myworld) C:UsersYourName>
Linux / macOS:
(myworld) $
• (myworld) indicates active environment
• All Python packages will install inside this environment
32.
Page 32
Check PythonInstallation
• Open Command Prompt / Terminal
• Run the command:
python --version
• If Python is installed, version is displayed
Example:
Python 3.13.2
33.
Page 33
What isPIP?
• PIP = Python Package Installer
• Used to install Python libraries and frameworks
• Comes bundled with Python version 3.4 and above
• Required to install Django
34.
Page 34
Check PIPInstallation
• Open Command Prompt / Terminal
• Run the command:
pip –version
• Example output:
pip 24.3.1 from ... (python 3.13)