Class-Based Views vs. Function-Based Views
- function-based views (FBVs)
- class-based views (CBVs)
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:
- simple is better than complex
- two scoops of Django : best practice for Django 1.8
网友评论