4 ms·
Is there any reason to still use them though? You could always just define a `get`, `post`, (etc etc) method and have pretty much the same effect of a functiona
by mumphster 14y ago
Is there any reason to still use them though? You could always just define a `get`, `post`, (etc etc) method and have pretty much the same effect of a functional view but with the added niceness of what CBV's provide (mainly inheriting some other view with a lot of boiler plate)
- shabda 14y agohttp://lukeplant.me.uk/blog/posts/djangos-cbvs-were-a-mistake/ http://lukeplant.me.uk/blog/posts/djangos-cbvs-were-a-mistak... http://lukeplant.me.uk/blog/posts/class-based-views-and-dry-ravioli/ http://lukeplant.me.uk/blog/posts/class-based-views-and-dry-... IMO, CBVs are good, but for many cases FBV are simpler to code and easier to understand.
- emperorcezar 14y agoDefining a get method on a class is just as simple and allows for future expansion.
- po 14y ago…future expansion that I will probably never use. And I disagree that it's just as simple. I think that CBV's encourage me (and my team, because I'm not working in a vacuum) to think about the problem all wrong. You may like thinking of the problem that way but for me it's like trying to think of a song while another song is playing. I usually think of Django views as a function, not a method on a class. Django's FBV's are far from perfect and I think they really could benefit from some small changes to the way things are done, but I agree with the above links that CBV's were a step in the wrong direction.
- emperorcezar 14y agoI'll have to just disagree with you here. I don't find the following any more difficult then a functional view class MyView(View): def get(self): return stuff It's one more line, and is much more explicit in what it handles.
- webjunkie 14y agoYou have no flow control in CBVs. Why code some methods and stuff when you can put it in a simple function?
- asadjb 14y ago“Sometimes, the elegant implementation is just a function. Not a method. Not a class. Not a framework. Just a function.” — John Carmack
- greghinch 14y agoI recently ran into issues which I could only explain as CBV not being thread safe. self.request.user would not remain consistent when a view needed to save multiple models. I haven't had time to fully debug, I only know that frantically patching to not rely on properties, rather arguments, fixed it. We're also running gunicorn on Heroku, not sure yet if that's related. Either way, something to consider.