On 01/09/11 21:46, Reinout van Rees wrote: > Passing the view object to the template by default seems to me to be an > absolute no-brainer. Class based views ought to mean you get the view > object in your template, right? But Django doesn't do it. So... is there > a specific reason for it?
Like Russell, I'd never thought of this idea before. The main argument I can think of against doing this is that it encodes an implementation detail into your templates. A template shouldn't know whether the data has come from a CBV or function, and shouldn't have to be changed if you go from one to the other or back again (both transitions being sensible in some circumstances). To me, this change would produce very strong coupling between the presentation logic and the view that produced it. The history of CBVs in Django is that they are simply a way of using OOP and inheritance to reduce duplication between view functions and allow better re-use. They are supposed to be drop in replacements for function based views in terms of the end result, rather than produce any change in what a template will contain. This means that CBVs and function based views are both first class citizens in Django world, and I for one prefer it that way. Slight digression: I do not think that CBVs are obvious winners for writing views. There are significant trade-offs and downsides, such as ravioli code, as I've blogged about before [1]. I've recently written an app from scratch using CBVs heavily, and it worked well, but 1) there were still times that functions were better, 2) there were some inheritance problems that required a small amount of fairly heavy-duty metaclass hackery to solve, 3) the code is less transparent to a newcomer. Regards, Luke [1] http://lukeplant.me.uk/blog/posts/class-based-views-and-dry-ravioli/ -- "Doubt: In the battle between you and the world, bet on the world." (despair.com) Luke Plant || http://lukeplant.me.uk/ -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.