🔹 Django Architecture
Django follows the MVT architecture (Model–View–Template).
It’s very similar to MVC, but with Django’s own naming.
- Model → Handles database access (ORM).
- View → Contains business logic (decides what data to send to the template).
- Template → Handles presentation (HTML, CSS, frontend rendering).
📌 Flow in Django (MVT):
- User requests a page → URL dispatcher routes to a view.
- View talks to Model (database).
- View passes data to Template.
- Template renders HTML page → sent back to browser.
👉 Example:
- Model =
Article
(database table) - View =
article_list
function - Template =
articles.html
🔹 DRF Architecture
Django REST Framework extends Django, but shifts the architecture focus.
Instead of MVT, it aligns more with MVC + REST principles.
In DRF, the architecture is usually described as Models – Serializers – Views:
- Model → Same as Django (ORM, database tables).
- Serializer → Converts complex data (Models, QuerySets) into JSON (and back).
- View → API endpoint (returns JSON instead of HTML).
📌 Flow in DRF (API call):
- Client (mobile app / React frontend) makes HTTP request (e.g.
/api/articles/
). - DRF View receives the request.
- View gets data from Model.
- Serializer converts model objects → JSON.
- Response is sent back as JSON.
🔹 Comparing Django vs DRF Architecture
Aspect | Django (MVT) | DRF (API-based) |
---|---|---|
Architecture | MVT (Model–View–Template) | MV(S)V (Model–View–Serializer) |
Output | HTML (via Templates) | JSON / XML / API response |
Frontend role | Django Templates handle views | External frontend (React, Vue, Flutter, Mobile apps) consumes JSON |
Extra layer | Templates | Serializers |
🔹 Quick Analogy
- Django = Chef prepares food (data) and serves it on a plate (HTML Template).
- DRF = Chef prepares food (data) but packs it in a box (JSON) so you can eat anywhere (React, mobile app, 3rd party).
✅ In short:
- Django = MVT (server-side rendered websites).
- DRF = Model–View–Serializer (API services with REST architecture).
Top comments (0)