I have a django blog app and am trying to put disqus on each of my pages with a single blog entry but all comments show up on all entries. I've looked at related questions and think my problem might be with get_absolute_url.
So originally I had this model and get_absolute_url set:
class posts(models.Model):
author = models.CharField(max_length = 30)
title = models.CharField(max_length = 100)
bodytext = models.TextField()
timestamp = models.DateTimeField()
slug = models.SlugField(max_length = 255)
description = models.TextField()
def __unicode__(self):
return self.bodytext
def get_absolute_url(self):
return reverse('blog.views.home')
This was simply returning a '/' as my get_absolute_url, and when I tried adding args it just returned an empty string...so I tried experimenting with:
def get_absolute_url(self):
return reverse('blog.views.single', args=[self.slug])
and
def get_absolute_url(self):
return reverse('single', args=[self.slug])
Which in the source code the Javascript disqus-url has something like 'single/secondentry' but the comments are still appearing on all of the entries.
So I think part of the problem might be that I simply don't understand what get_absolute_url is supposed to be. After googling and reading the docs I thought it would be the url to my homepage('blog.views.home') but when I set it as that, if I add any arguments it just returns an empty string.
Here are my urls for home and single pages:
url(r'^$', 'blog.views.home', name='home'),
url(r'^$', 'blog.views.index', name='index'),
url(r'^single/(?P<slug>[\w-]+)/$', 'blog.views.single', name='single'),
...
For the immediate problem here, the disqus Javascript elements seem to be getting assigned correctly otherwise, so I'm not sure why the comments are still showing up on all of the entries.
var disqus_shortname = 'sitename';
var disqus_developer = "1";
var disqus_identifier = "1";
var disqus_url = "/single/first/";
var disqus_title = "First post";
return reverse('single', args=[self.slug])
. Also, do you have a namespace specified forblogs
in Root URL conf ? – karthikrkwargs
. – Games Brainiac