美文网首页
Django高级(五):视图高级

Django高级(五):视图高级

作者: 宇辰星君 | 来源:发表于2017-04-06 16:42 被阅读59次

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

    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:

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

    相关文章

      网友评论

          本文标题:Django高级(五):视图高级

          本文链接:https://www.haomeiwen.com/subject/qayqattx.html