5.9.1 Comparing Class-Based Views to Functions Views

A CBV can do everything a function view can do. We’ve not seen the use of the URL pattern dictionary previously, and so we’ll now take the opportunity to use a dictionary in both a function view and a CBV to demonstrate similarities. The practical purpose of our dictionary is to override the base template of our view (which we defined in Chapter 4 in the template as parent_template), and the learning purpose is to familiarize you with the URL pattern dictionary and CBVs.

To start, we add the dictionary to both blog URL patterns, as shown in Example 5.59.

Example 5.59: Project Code

blog/urls.py in d3030ee8d3

 5  urlpatterns = [  6      url(r'^$',  7          PostList ...

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.