O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.9.3 View Internals

CBVs also come with several much subtler advantages. To best understand these advantages, it’s worth diving into the internals of View and seeing exactly what we’re inheriting when we create a CBV.

The easiest place to start is with as_view(). In a URL pattern, we use as_view() to reference the CBV. Example 5.66 shows an example generic URL pattern.

Example 5.66: Python Code

url(r'^(?P<slug>[\w\-]+)/$',     CBV.as_view(class_attribute=some_value),     {'dict_key': 'dict_value'},     name='app_model_action')

The as_view() method is a static class method (note that we call PostList.as_view() and not PostList().as_view()) and acts as a factory; as_view() returns a view (a method on the instance ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required