SlideShare uma empresa Scribd logo
1 de 7
MODEL-VIEW-CONTROLLER
(MVC) PATTERN IN DJANGO
www.studysection.com
INTRODUCTION
Django uses the Model-View-Controller (MVC) pattern, with slight variations,
primarily following the Model-Template-View (MTV) pattern. This structure
enhances developer productivity and maintainability. Models represent the
data layer, View handles presentation logic, and Controller coordinates
interactions. MTV maintains data-related tasks, while Views serve as
Controllers, promoting maintainable code and modularity in Django web
applications. the data layer, View handles presentation logic, and Controller
coordinates interactions. MTV maintains data-related tasks, while Views
serve as Controllers, promoting maintainable code and modularity in Django
web applications.
DJANGO ARCHITECTURE
COMPONENTS
• Django's Model is the data layer, encapsulating application
structure, ensuring integrity, and handling database interaction,
defined as Python classes inheriting from
django.db.models.Model.
• Django's Views are Python functions that handle incoming
requests, data retrieval, and rendering, encapsulating application
logic and handling business logic, determining data display and
user response.
• Django templates, like the View component in MVC, generate the
application's presentation layer, containing HTML markup,
embedded tags, and filters, dynamically rendering data and
sending output to the client's web browser.
Simplified example of a
Django model
from django.db import models
class Post(models.Model):
title =models.CharField(max_length=100)
content = models.TextField()
created_at =
models.DateTimeField(auto_now_add=True)
Example of a Django View
Function: from django.http
import HttpResponse def hello(request):
return HttpResponse("Hello, Django!")
from django.shortcuts import render
from .models import Product
Example of a Django
Template:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-
scale=1.0">
<title>My Template</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
TO READ MORE ON THIS TOPIC
Do visit: https://studysection.com/blog
www.studysection.com

Mais conteúdo relacionado

Semelhante a Model-View-Controller (MVC) Pattern in Django

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoKnoldus Inc.
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django frameworkKnoldus Inc.
 
Mcv design patterns
Mcv design patternsMcv design patterns
Mcv design patternsRob Paok
 
Single page application 03
Single page application   03Single page application   03
Single page application 03Ismaeel Enjreny
 
OOAD_CH_04_mvc-architecture.pdf
OOAD_CH_04_mvc-architecture.pdfOOAD_CH_04_mvc-architecture.pdf
OOAD_CH_04_mvc-architecture.pdfZahidAkon2
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworksMukesh Kumar
 
Unleash-the-power-of-Django.pptx
Unleash-the-power-of-Django.pptxUnleash-the-power-of-Django.pptx
Unleash-the-power-of-Django.pptxShivamSv1
 
Workshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVCWorkshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVCVisual Engineering
 
Pattern oriented architecture for web based architecture
Pattern oriented architecture for web based architecturePattern oriented architecture for web based architecture
Pattern oriented architecture for web based architectureshuchi tripathi
 
Android DesignArchitectures.pptx
Android DesignArchitectures.pptxAndroid DesignArchitectures.pptx
Android DesignArchitectures.pptxSafnaSaff1
 
Django Frequently Asked Interview Questions
Django Frequently Asked Interview QuestionsDjango Frequently Asked Interview Questions
Django Frequently Asked Interview QuestionsAshishMishra308598
 
Kalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js TutorialsKalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js TutorialsKalp Corporate
 
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patternsallanh0526
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: AndroidJitendra Kumar
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoAhmed Salama
 

Semelhante a Model-View-Controller (MVC) Pattern in Django (20)

Angular introduction basic
Angular introduction basicAngular introduction basic
Angular introduction basic
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django framework
 
Angular Basics.pptx
Angular Basics.pptxAngular Basics.pptx
Angular Basics.pptx
 
Django framework
Django frameworkDjango framework
Django framework
 
Mcv design patterns
Mcv design patternsMcv design patterns
Mcv design patterns
 
Single page application 03
Single page application   03Single page application   03
Single page application 03
 
MVC in PHP
MVC in PHPMVC in PHP
MVC in PHP
 
OOAD_CH_04_mvc-architecture.pdf
OOAD_CH_04_mvc-architecture.pdfOOAD_CH_04_mvc-architecture.pdf
OOAD_CH_04_mvc-architecture.pdf
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
Unleash-the-power-of-Django.pptx
Unleash-the-power-of-Django.pptxUnleash-the-power-of-Django.pptx
Unleash-the-power-of-Django.pptx
 
MVC & backbone.js
MVC & backbone.jsMVC & backbone.js
MVC & backbone.js
 
Workshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVCWorkshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVC
 
Pattern oriented architecture for web based architecture
Pattern oriented architecture for web based architecturePattern oriented architecture for web based architecture
Pattern oriented architecture for web based architecture
 
Android DesignArchitectures.pptx
Android DesignArchitectures.pptxAndroid DesignArchitectures.pptx
Android DesignArchitectures.pptx
 
Django Frequently Asked Interview Questions
Django Frequently Asked Interview QuestionsDjango Frequently Asked Interview Questions
Django Frequently Asked Interview Questions
 
Kalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js TutorialsKalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js Tutorials
 
iOS architecture patterns
iOS architecture patternsiOS architecture patterns
iOS architecture patterns
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 

Mais de StudySection

Understanding Requirements Traceability Matrix (RTM).pdf
Understanding Requirements Traceability Matrix (RTM).pdfUnderstanding Requirements Traceability Matrix (RTM).pdf
Understanding Requirements Traceability Matrix (RTM).pdfStudySection
 
Laravel Eloquent: Empowering Database Interactions with Elegance
Laravel Eloquent: Empowering Database Interactions with EleganceLaravel Eloquent: Empowering Database Interactions with Elegance
Laravel Eloquent: Empowering Database Interactions with EleganceStudySection
 
Comparison of Function Components and Class Components in React.js
Comparison of Function Components and Class Components in React.jsComparison of Function Components and Class Components in React.js
Comparison of Function Components and Class Components in React.jsStudySection
 
Explore The Effective Caching Strategies
Explore The Effective Caching StrategiesExplore The Effective Caching Strategies
Explore The Effective Caching StrategiesStudySection
 
What is a microservices architecture in Laravel?
What is a microservices architecture in Laravel?What is a microservices architecture in Laravel?
What is a microservices architecture in Laravel?StudySection
 
Unveiling the PHP Application Controller Paradigm
Unveiling the PHP Application Controller ParadigmUnveiling the PHP Application Controller Paradigm
Unveiling the PHP Application Controller ParadigmStudySection
 
Unveil the Power of Socket.IO in Node.js
Unveil the Power of Socket.IO in Node.jsUnveil the Power of Socket.IO in Node.js
Unveil the Power of Socket.IO in Node.jsStudySection
 
Software Process Improvement and Capability Determination (SPICE)
Software Process Improvement and Capability Determination (SPICE)Software Process Improvement and Capability Determination (SPICE)
Software Process Improvement and Capability Determination (SPICE)StudySection
 
Software Process Improvement and Capability Determination.pdf
Software Process Improvement and Capability Determination.pdfSoftware Process Improvement and Capability Determination.pdf
Software Process Improvement and Capability Determination.pdfStudySection
 
Explain the Two-Step View pattern with an example in PHP.docx
Explain the Two-Step View pattern with an example in PHP.docxExplain the Two-Step View pattern with an example in PHP.docx
Explain the Two-Step View pattern with an example in PHP.docxStudySection
 
The Imperatives of Cross-Browser Testing
The Imperatives of Cross-Browser TestingThe Imperatives of Cross-Browser Testing
The Imperatives of Cross-Browser TestingStudySection
 
Implementation of the Data Mapper Pattern in Python.docx
Implementation of the Data Mapper Pattern in Python.docxImplementation of the Data Mapper Pattern in Python.docx
Implementation of the Data Mapper Pattern in Python.docxStudySection
 
JavaScript Overview_ Features, History, Advantages, and Limitations.docx
JavaScript Overview_ Features, History, Advantages, and Limitations.docxJavaScript Overview_ Features, History, Advantages, and Limitations.docx
JavaScript Overview_ Features, History, Advantages, and Limitations.docxStudySection
 

Mais de StudySection (13)

Understanding Requirements Traceability Matrix (RTM).pdf
Understanding Requirements Traceability Matrix (RTM).pdfUnderstanding Requirements Traceability Matrix (RTM).pdf
Understanding Requirements Traceability Matrix (RTM).pdf
 
Laravel Eloquent: Empowering Database Interactions with Elegance
Laravel Eloquent: Empowering Database Interactions with EleganceLaravel Eloquent: Empowering Database Interactions with Elegance
Laravel Eloquent: Empowering Database Interactions with Elegance
 
Comparison of Function Components and Class Components in React.js
Comparison of Function Components and Class Components in React.jsComparison of Function Components and Class Components in React.js
Comparison of Function Components and Class Components in React.js
 
Explore The Effective Caching Strategies
Explore The Effective Caching StrategiesExplore The Effective Caching Strategies
Explore The Effective Caching Strategies
 
What is a microservices architecture in Laravel?
What is a microservices architecture in Laravel?What is a microservices architecture in Laravel?
What is a microservices architecture in Laravel?
 
Unveiling the PHP Application Controller Paradigm
Unveiling the PHP Application Controller ParadigmUnveiling the PHP Application Controller Paradigm
Unveiling the PHP Application Controller Paradigm
 
Unveil the Power of Socket.IO in Node.js
Unveil the Power of Socket.IO in Node.jsUnveil the Power of Socket.IO in Node.js
Unveil the Power of Socket.IO in Node.js
 
Software Process Improvement and Capability Determination (SPICE)
Software Process Improvement and Capability Determination (SPICE)Software Process Improvement and Capability Determination (SPICE)
Software Process Improvement and Capability Determination (SPICE)
 
Software Process Improvement and Capability Determination.pdf
Software Process Improvement and Capability Determination.pdfSoftware Process Improvement and Capability Determination.pdf
Software Process Improvement and Capability Determination.pdf
 
Explain the Two-Step View pattern with an example in PHP.docx
Explain the Two-Step View pattern with an example in PHP.docxExplain the Two-Step View pattern with an example in PHP.docx
Explain the Two-Step View pattern with an example in PHP.docx
 
The Imperatives of Cross-Browser Testing
The Imperatives of Cross-Browser TestingThe Imperatives of Cross-Browser Testing
The Imperatives of Cross-Browser Testing
 
Implementation of the Data Mapper Pattern in Python.docx
Implementation of the Data Mapper Pattern in Python.docxImplementation of the Data Mapper Pattern in Python.docx
Implementation of the Data Mapper Pattern in Python.docx
 
JavaScript Overview_ Features, History, Advantages, and Limitations.docx
JavaScript Overview_ Features, History, Advantages, and Limitations.docxJavaScript Overview_ Features, History, Advantages, and Limitations.docx
JavaScript Overview_ Features, History, Advantages, and Limitations.docx
 

Último

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Último (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Model-View-Controller (MVC) Pattern in Django

  • 1. MODEL-VIEW-CONTROLLER (MVC) PATTERN IN DJANGO www.studysection.com
  • 2. INTRODUCTION Django uses the Model-View-Controller (MVC) pattern, with slight variations, primarily following the Model-Template-View (MTV) pattern. This structure enhances developer productivity and maintainability. Models represent the data layer, View handles presentation logic, and Controller coordinates interactions. MTV maintains data-related tasks, while Views serve as Controllers, promoting maintainable code and modularity in Django web applications. the data layer, View handles presentation logic, and Controller coordinates interactions. MTV maintains data-related tasks, while Views serve as Controllers, promoting maintainable code and modularity in Django web applications.
  • 3. DJANGO ARCHITECTURE COMPONENTS • Django's Model is the data layer, encapsulating application structure, ensuring integrity, and handling database interaction, defined as Python classes inheriting from django.db.models.Model. • Django's Views are Python functions that handle incoming requests, data retrieval, and rendering, encapsulating application logic and handling business logic, determining data display and user response. • Django templates, like the View component in MVC, generate the application's presentation layer, containing HTML markup, embedded tags, and filters, dynamically rendering data and sending output to the client's web browser.
  • 4. Simplified example of a Django model from django.db import models class Post(models.Model): title =models.CharField(max_length=100) content = models.TextField() created_at = models.DateTimeField(auto_now_add=True)
  • 5. Example of a Django View Function: from django.http import HttpResponse def hello(request): return HttpResponse("Hello, Django!") from django.shortcuts import render from .models import Product
  • 6. Example of a Django Template: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial- scale=1.0"> <title>My Template</title> </head> <body> <h1>Hello, World!</h1> </body> </html>
  • 7. TO READ MORE ON THIS TOPIC Do visit: https://studysection.com/blog www.studysection.com