Skip to Main Content
Hands-On Application Development with PyCharm
book

Hands-On Application Development with PyCharm

by Quan Nguyen
September 2019
Beginner to intermediate content levelBeginner to intermediate
494 pages
13h
English
Packt Publishing
Content preview from Hands-On Application Development with PyCharm

Creating Django's detail views

A detail view is a way to specify what should be included and displayed on a web page. This corresponds to one specific model object. Here, we will add in the logic for listing and viewing the content of the individual blog posts that have been saved in our database. First, we need to extend the logic of the Post class:

  1. In the blog/models.py file, add the following method to our current Post class:
from django.urls import reverseclass Post(models.Model):    ...    def get_absolute_url(self):        return reverse('blog:post_detail', args=[            self.publish_date.year,            self.publish_date.strftime('%m'),            self.publish_date.strftime('%d'),            self.slug        ])

Here, we are specifying that when a Post object calls its get_absolute_url() ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

MASTERING PYCHARM

MASTERING PYCHARM

Nafiul Islam

Publisher Resources

ISBN: 9781789348262Supplemental Content