On 3 December 2010 22:40, Andrew Willey <and...@apt9online.com> wrote:
> So it works as
>
>> url(r'^location/$', WouldLoveToHaveClassBasedView.as_view(), 
>> name='name_for_convenience')
>
> Didn't realize I could just pass the class object.  Makes sense.
> Guess I'm getting old and change fearing.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to