Django高级(五):视图高级

2017-04-06  本文已影响59人  宇辰星君

https://simpleisbetterthancomplex.com/article/2017/03/21/class-based-views-vs-function-based-views.html

Class-Based Views vs. Function-Based Views

1. When to use FBVs or CBVs

Whenever you implement a view, think about whether it would make more sense to implement as a FBV or as a CBV.

这里写图片描述

We prefer to use CBVs for most views, using FBVs to implement only the custom error views or complicated ones that would be a pain to implement with CBVs.
原则:优先选择CBVs,只有CBVs解决起来麻烦的复杂视图才交给FBVs。


Reference:

  1. simple is better than complex
  2. two scoops of Django : best practice for Django 1.8
上一篇 下一篇

猜你喜欢

热点阅读