To be clear here - you're not passing the class object here -
as_view() returns a normal function that takes care of everything:
creating a View instance and passing request and URL params to it's
dispatch method. Class-based views get no special handling in Django,
so you could just copy the 'django.views.generic' package to your
Django<1.3 project and use them (I did :).
>
> I think the only thing that's bugging me is that you have to include
> the whole views.py in your url conf. Just feels less graceful than
> having the dispatcher nab what it needs on demand. I'll get over it.
You should avoid doing "from ... import *" and just explicitly name
the views you need. It's easier to see which views are actually used
this way. If you really want to use the string syntax:
# views.py
my_view = MyView.as_view()
# urls.py
urlpatterns('myapp.views',
url(r'some_pattern/', 'my_view', name="myapp-my_view")
)
There is not way to use a string like 'myapp.views.MyView' - you need
the alias. Also, you most likely want to name all your URL patterns
that use class-based views or you won't have a way to use reverse()
with them.
--
Łukasz Rekucki