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:
- 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() ...