views:

24

answers:

1

I am having issues with get_absolute_url in my django templates when using django page cms. It returns an empty string and does not link to my required page.

I have the following Models, URLs templates and views

Models

class Body(models.Model):
...
url = models.SlugField(unique=True, help_text='---')

urls

(r'^news/', include('news.urls_news')),......

url(r'^/(?P<url>[\w\-]+)/$', 'news_view', name='news_view'),    

View

def news_view(request, url):
new = get_object_or_404(Body, url=url)
return render_to_response('news/view.html', {
    'news': news
}, context_instance=RequestContext(request))

Template

   <li><a href="{{ news.get_absolute_url }}">{{ news.title }}</a></li>

the following code in my template returns the string I desire however this does to direct to my html page

   <li><a href="{{ news.url }}">{{ news.title }}</a></li>

I know my everything links to the correct files because I have other views that work correctly. Could somebody please point me in the correct direction as to why get_absolute_url is not working correctly and why {{ news.url }} does not direct to the correct page. I am sure it has something to do with my urls.py however I am not certain. Please bear with me I am new to django. All help is greatly appreciated.

+1  A: 

Have you actually defined a get_absolute_url method on the News model? You don't show it.

Daniel Roseman
Yes it was that coupled with the fact I had ordered my URLs in the wrong order. I did not think that the ordering of URLS mattered however it does. cheers.
Rick