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.
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 ...
Get Django Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.