[Answer]-ImportError when using get_absolute_url

1πŸ‘

βœ…

In get_absolute_url you forgot to call reverse on the url. You are passing the tuple back which is makes it invalid. Your get_absolute_url should be:

from django.core.urlresolvers import reverse

def get_absolute_url(self):
        creation_date = timezone.localtime(self.start_publication)
        return reverse('entry_detail', kwargs={
            'year': creation_date.strftime('%Y'),
            'month': creation_date.strftime('%b').lower(),
            'day': creation_date.strftime('%d'),
            'slug': self.slug})

permalink decorator is deprecated and the use of reverse is recommended

πŸ‘€karthikr

0πŸ‘

You have an error somewhere else in your project, in an app that is referenced in urls.py.

The reverse URL lookup functionality (which you’ve implicitly used by using the @permalink decorator) has to import all views referenced in your urls.py file in order to calculate the correct value. If you have an error somewhere, it will fail.

You should find the reference to app2, wherever it is, and fix it.

Leave a comment