Modifying the canonical URL for posts
We also have to modify the parameters of the canonical URL for blog posts to match the new URL parameters.
…
- Edit the
models.py
file of theblog
application and edit theget_absolute_url()
method as follows:
class Post(models.Model):
# ...
def get_absolute_url(self):
return reverse('blog:post_detail',
args=[self.publish.year,
self.publish.month,
self.publish.day,
self.slug])
- Start the development server by typing the following command in the shell prompt:
python manage.py runserver
- Next, you can return to your browser and click on one of the post titles to take a look at the detail view of the post. You should see something like this:
Take a look at the URL—it should look like /blog/2024/1/1/who-was-django-reinhardt/
. You have designed...