Function-based Views vs Class-based Views

52 views
Skip to first unread message

Michael Starr

unread,
Mar 6, 2023, 3:19:21 PM3/6/23
to Django users
What are the pros and cons of either method of rendering HTTP request responses?


In the article above it states that CBVs are DRYer, but I don't understand why. The article doesn't explain, it just states it.

The rest of the article is pretty good but it's a pretty slim introduction.

I thought many of you would like to chime in on this topic. Leave your opinion below! What do you use?

Mike

Prosper Lekia

unread,
Mar 6, 2023, 4:04:59 PM3/6/23
to Django users
Using classes is always a good way of promoting code usability, and inheritance. With class base views you don't need to reinvent the wheel. You can access other  Django classes and methods and reduce code complexity. Although most codes are encapsulated, but you can always go back to the Django source code for review.

Carsten Fuchs

unread,
Mar 7, 2023, 1:59:26 AM3/7/23
to django...@googlegroups.com
I would like to recommend this excellent guide by Luke Plant:

https://spookylukey.github.io/django-views-the-right-way/

Best regards,
Carsten


Am 06.03.23 um 21:19 schrieb Michael Starr:

Michael Starr

unread,
Mar 7, 2023, 1:22:36 PM3/7/23
to Django users
I'll read this once I'm feeling less fatigues. Thank you both for sharing.
Michael
Reply all
Reply to author
Forward
0 new messages