[Fixed]-Errors with django urls

1👍

Your get_absolute_url method returns URLs in the form /posts/<id> but your urlconf is expecting /posts/detail/<id>.

Instead of hard-coding a URL like that in the method, you should use the reverse functionality:

from django.urls import reverse
...
def get_absolute_url(self):
    return reverse('detail', kwargs={'id': self.id})

Leave a comment