0

I'm new to Django development, so I want to ask people who have more practice - what do they use more often? I'm of course assuming it's CBV since it's easier for others to read, but I'll ask anyway.

thanks in advance for your reply

kaliboba
  • 11
  • 5
  • 1
    Does this answer your question? [Class Based Views VS Function Based Views](https://stackoverflow.com/questions/14788181/class-based-views-vs-function-based-views) – Adamu Dee Azare Jun 07 '23 at 10:55

3 Answers3

1

As always, it depends on the project.

I'd go with CBV as it favors readability, reusability and supports inheritance.

It's also using CBV that most libs expanding views will work.

1

My opinion of ( FBV or CBV )

=> if I want to create only web API's then I prefer CBV

But,

=> I want to work with Django Templates and then use FBV, but it depends on and requirements because sometimes I feel the need only simple CRUD Operation then I prefer CBV not to require more validation or logic

0

It's mostly a matter of opinion. Mine is that CBVs are easier to write and MUCH less prone to errors, even if they are typically more (but simpler) lines of code.

Some complicated views just don't fit into the pattern the standard CBVs even with a lot of sub-classing. In this case, write an FBV.

Some extremely simple views may also be regarded as more easily represented as an FBV.

An invaluable resource for CBVs is Classy Class-based views, which is everything you need to know to subclass with confidence!

nigel222
  • 7,582
  • 1
  • 14
  • 22