5.8.6 Building a Post Detail Page

The final view left to program is our detail view of a single Post object. Programming the view and URL pattern for this view is a little bit trickier than our other views: the URL for each Post object is based not only on the slug but also on the date of the object, making the regular expression pattern and query to the database a little more complicated. Recall that we are enforcing this behavior in our Post model via the unique_for_month attribute on the slug.

Take http://site.django-unleashed.com/blog/2013/1/django-training/ as an example. After include() in our root URL configuration truncates blog/ from the URL path, our blog app URL configuration will receive 2013/1/django-training/. Our regular expression ...

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.