Home  >  Q&A  >  body text

About class-based views in django and flask?

I was reading the Flask documentation recently and found that in Django and Flask, views are both based on functions and classes (called plug-in views in Flask). I don’t quite understand the difference between these two views. Since I have just started, I have always used functional views. What is the difference between these two views? In formal development, are functional views or class-based views used more?

欧阳克欧阳克2675 days ago706

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-22 11:53:58

    There is no difference, it’s just a different style when writing code.

    Class-based views emphasize defining all views in one place,
    Function-based views are defined where they are used.

    reply
    0
  • 阿神

    阿神2017-06-22 11:53:58

    Class-based views facilitate logic reuse. You can write common logic in multiple views in a base class, and the view class that inherits this base class can have this logic.

    reply
    0
  • Cancelreply