MVC
傳統(tǒng)的MVC模式指的是model,view,controller
- model是用來和數(shù)據(jù)庫交互献酗,存取數(shù)據(jù)的
- view是數(shù)據(jù)的呈現(xiàn)方式
- controller就是接受request蠢莺,然后從model取得數(shù)據(jù),再傳遞給view最終實現(xiàn)數(shù)據(jù)的呈現(xiàn)蝇闭。
MVT
Django中的MVT模式指的是model呻率,view,template
- model中呻引,Django有內(nèi)建的orm礼仗,可以用python語言來編寫數(shù)據(jù)庫table的schema,并且存取刪除更新數(shù)據(jù)庫中的數(shù)據(jù)逻悠。
- view 在Django 指的是哪些數(shù)據(jù)要呈現(xiàn)元践,而不是怎樣呈現(xiàn),這是和傳統(tǒng)MVC很不同的一點童谒。
- template 在Django就類似傳統(tǒng)的MVC中的view单旁,定義如何呈現(xiàn)數(shù)據(jù)
- Django沒有明確的controller,因為Django本身就是一個controller惠啄,它得到用戶的request請求慎恒,使用url match來向合適的view發(fā)送請求任内,view再和model交互得到數(shù)據(jù),處理完數(shù)據(jù)后融柬,發(fā)送給template完成數(shù)據(jù)的呈現(xiàn)死嗦。
Django is a "MTV" framework – that is, “model”, “template”, and “view.”
The "view"
describes the data that gets presented to the user. It’s not necessarily how the data looks, but which data is presented. The view describes which data you see, not how you see it. It’s a subtle distinction.
So, in our case, a view
is the Python callback function for a particular URL, because that callback function describes which data is presented.
Furthermore, it’s sensible to separate content from presentation – which is where templates come in. In Django, a view
describes which data is presented, but a view normally delegates to a template
, which describes how the data is presented.
Where does the controller
fit in, then? In Django’s case, it’s probably the framework itself: the machinery that sends a request to the appropriate view, according to the Django URL configuration.
Reference:
https://docs.djangoproject.com/en/1.11/faq/general/