Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Function based views are good until you have to handle many request methods, then they become a hideous series of if/elif/else.


> series of if/elif/else

in my personal experience this can also happen when using class based. It depends on how much your application is "CRUD-y"

with a CRUD, it's easier to go CBV and have minimal branching, and use the different HTTP verbs based on the CRUD operations.

but sometimes you have apps where you have a bunch of different operations, and maybe all of those operations are just types of updates to the same type "Foo".

in that case, FBVs work best, because you can just do

def update_foo_expiry()

def renew_foo()

def rename_foo()

etc. etc. - all of the above would have ended up being if/elif/else in a put() method in a CBV


If you would have made them separate function views, they should be separate class views.


Or a good opportunity for match/case if >3.9.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: