[Answer]-Rewrite get_absolute_url method in a template- django 1.6.5

1👍

You are attempting to pass the name of the urls as an argument, when they should be a keyword argument, specifying name. So, an example would be as follows:

url(r'^$', 'index', {'template_name': 'catalog/index.html'}, name='catalog_home'),

So, now when you call from a view:

reverse('catalog_home') or from your template {% url 'catalog_home' %}

Django will search through your urls.py for a url with the name 'catalog_home', and correctly find it.

And Alasdair is correct that it was most likely a url found earlier in the template that threw this error, rather than where you thought the error occurred.

Also, somewhat unrelated, but the standard that you will find through out the Django docs, is to name your urls using dashes (-), rather than underscores. So 'catalog_home' would be 'catalog-home'

👤Johndt

0👍

Thankyou folks for help.
Writing the urls as url(r'^$', 'index', {'template_name': 'catalog/index.html'}, name='catalog_home'), and removing @permalink from the get_absolute_url() method definitions helped.
This code was written using a tutorial for the older version of Django,and @permalink is not used,or required anymore!
Instead, if one still wishes to use:

get_absolute_url = models.permalink(get_absolute_url)

with the get_absolute_function() definition (version 1.4 onwards).

Leave a comment