官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 绥棱县| 太仓市| 黑河市| 崇文区| 安达市| 泌阳县| 泾阳县| 静宁县| 叶城县| 宣恩县| 永善县| 久治县| 开鲁县| 双城市| 岑溪市| 龙门县| 沙洋县| 临猗县| 靖边县| 平乐县| 上饶市| 新安县| 巴林左旗| 达州市| 尤溪县| 商南县| 嘉荫县| 安新县| 芜湖县| 石河子市| 安丘市| 灵川县| 湛江市| 蓝山县| 天柱县| 齐齐哈尔市| 吉林省| 正阳县| 曲阜市| 佛冈县| 济源市|