- Django Design Patterns and Best Practices
- Arun Ravindran
- 294字
- 2021-06-25 21:32:00
Is Django MVC?
Model-View-Controller (MVC) is an architectural pattern invented by Xerox PARC in the 70s. Being the framework used to build user interfaces in Smalltalk, it gets an early mention in the GoF book.
Today, MVC is a very popular pattern in web application frameworks. A variant of the common question is whether Django is an MVC framework.
The answer is both yes and no. The MVC pattern advocates the decoupling of the presentation layer from the application logic. For instance, while designing an online game website API, you might present a game's high scores table as an HTML, XML, or comma-separated values (CSV) file. However, its underlying model class would be designed independently of how the data would be finally presented.
MVC is very rigid about what models, views, and controllers do. However, Django takes a much more practical view to web applications. Due to the nature of the HTTP protocol, each request for a web page is independent of any other request. Django's framework is designed like a pipeline to process each request and prepare a response.
Django calls this the Model-Template-View (MTV) architecture. There is a separation of concerns between the database interfacing classes (model), request-processing classes (view), and a templating language for the final presentation (template).
If you compare this with the classic MVC — a model is comparable to Django's Models; a view is usually Django's Templates, and the controller is the framework itself that processes an incoming HTTP request and routes it to the correct view function.
If this has not confused you enough, Django prefers to name the callback function to handle each URL a view function. This is, unfortunately, not related to the MVC pattern's idea of a view.
- Learning C# by Developing Games with Unity 2020
- Python科學計算(第2版)
- C語言程序設計案例教程(第2版)
- C# 2012程序設計實踐教程 (清華電腦學堂)
- Web Application Development with MEAN
- 教孩子學編程:C++入門圖解
- Troubleshooting PostgreSQL
- Python編程與幾何圖形
- INSTANT Django 1.5 Application Development Starter
- 零基礎趣學C語言
- 編程菜鳥學Python數據分析
- Python項目實戰從入門到精通
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動化處理
- R語言數據挖掘:實用項目解析
- Greenplum構建實時數據倉庫實踐