Profile photo for Michael Herman

Pros of using Class-Based Views (CBVs) in Django:

  1. Code reusability: You can reuse your code anywhere in your project — i.e., a view class can be inherited by another view class.
  2. Reduced Code Duplication: Keeping it DRY! Again, rather than writing the same code over and over again, you can have your views inherit from a base view.
  3. Well-structured code: Who doesn't like readable code? With CBVs, you can restructure and refactor your code to make it more pleasant and appealing by “hiding” unnecessary code in parent classes and/or mixins.
  4. Extensibility: Your code can be extended with mixins to include more functionalities.

Cons:

  1. Readability: Hiding code in parent classes can make your code more elegant, but readability (and understandability) can suffer since not all the code is readily available in a single location.
  2. Overkill: If the view has a one-off functionality, it's probably overkill to use CBVs. Use them in places where you know you’ll need to reuse a portion of code across multiple views.
  3. Decorators: It’s harder to implement view decorators with CBVs as they require extra imports.

Django ships with a number of generic view classes that are great for common tasks. If you can take advantage of them either by themselves or with a few overrides, I would start with them. From there, I generally go with Function-based Views (FBVs). If I find myself writing the same code again and again across multiple views, I’ll then look to refactor them into CBVs.

View question
About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025