On Sat, 2010-10-23 at 12:57 +0200, Łukasz Rekucki wrote: > Hi, > > I just started my "academic adventure". The goal is to refactor some > of existing contrib and 3rd party apps to CBV to get a better feel of > the API in real-world. Don't worry, I'm not going to spam this list > with every problem I encountered, but there are two things I stumbled > on upon almost instantly: > > 1) You can't put CBV in your urls.py using a string like you could > with function views. This forces you to import every CBV, which is a > bit annoying.
You can do it if you do something like this in your views.py: my_view = MyView.as_view() That way you export your view as both a function to be used as a view directly, and a class for further re-use. If your CBV cannot be used directly (e.g. needs to be subclassed), then it will have to imported by someone in order to be used anyway, and they can do the step above. In some cases, especially where you are simply wanting to include someone else's app with a small amount of customisation, that brings up the question of where to put that view definition. One solution is to have a 'project' app which has a views.py all these bits and pieces in it. To me, that seems like a nicer idea than filling urls.py with bloat. If this was established as a convention, then the problem with reverse() would be addressed as well. Luke -- "If you do a job badly enough, sometimes you don't get asked to do it again." (Calvin and Hobbes) 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-develop...@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.