9

Basically, the same Disqus comments are showing up for every post. I've read about why this occurs, and still cannot figure out what is going wrong.

Here's what I'm seeing on my page: 1

And here's my template code:

{% block content %}
    <p> The post id is: {{ post_object.id}} </p>
    <p> The post URL: {{ post_object.get_absolute_url }}


    {# DISQUS #}
    <div id="disqus_thread"></div>
    <script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'MySiteName'; // required
    var disqus_identifier = '{{ post_object.id }}';
    var disqus_url = 'http://localhost:8000{{ post_object.get_absolute_url }}';
    var disqus_title = '{{ post_object.title }}';
    var disqus_developer = 1;        

/* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
{% endblock content %}

Rendered HTML:

<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'MySiteName'; // required
var disqus_identifier = '42';
var disqus_url = 'http://localhost:8000/post/42/';
var disqus_title = 'Test post';
var disqus_developer = 1;

/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

As you can see, the disqus_identifier and disqus_url are unique. What is going on here?

Any ideas or feedback help! Thanks!


EDIT: Alright, I see where the problem is coming from. After posting on a comment on a post located at say http://localhost:8000/post/42/, Disqus adds to the Disqus admin (under the 'Discussions tab') the link to the post as http://localhost:8000/post

This is not even a valid URL on my page. When I explicitly change the link to http://localhost:8000/post/42/, it saves. However, a newly created post will still display the comments from post 42.

Thoughts?

dm03514
  • 54,664
  • 18
  • 108
  • 145
chipperdrew
  • 403
  • 4
  • 11
  • What does the HTML of the rendered template look like? Are the variables substituted as you expect? – Alasdair Jul 13 '13 at 14:14
  • Good thought. I added that above, however it appears as it should. – chipperdrew Jul 13 '13 at 18:43
  • 1
    I think I see where my problems lies. On Disqus's Admin site, under 'Discussions' tab, it is assigning the post the url `http://localhost:8000/post`. All of the posts are located at `http://localhost:8000/post/SOME_NUMBER`, therefore since all posts are subsets of the `/post` domain, the comments aren't unique to a post. – chipperdrew Jul 13 '13 at 18:58
  • @chipperdrew, did you find out why the url was showing up as `/post` in Discussions tab? I'm having the same issue, spent hours on it so far, extremely frustrating – dm03514 Oct 11 '13 at 18:55
  • 1
    Can you try on a staging server? Disqus might check the response on the URL you're providing... – François Constant Oct 14 '13 at 06:55
  • See here: http://stackoverflow.com/questions/9475821/disqus-comments-fails-to-load-on-localhost (the most recent response, not the accepted one) – François Constant Oct 14 '13 at 07:01
  • @dm03514 I never figured it out. I ended up giving up on Disqus since it was frustrating me so much. Best of luck to you! – chipperdrew Oct 17 '13 at 04:02
  • Should the question be closed then? We won't be able to get a confirmation of the answer if the person asking has left the issue? – Joe Nov 08 '13 at 20:35

2 Answers2

5

Install django-disqus and use it in your templates.

pip install django-disqus

Add disqus to your INSTALLED_APPS and put your disqus api key in your settings:

settings.py

INSTALLED_APPS = (
    ...
    'disqus',
    ...
)

DISQUS_API_KEY = 'YOUR_SECRET_API_KEY'
DISQUS_WEBSITE_SHORTNAME = 'YOUR_WEBSITE_SHORTNAME'

Use disqus template tags in your templates:

some_template.html

# load the tags
{% load disqus_tags %}
# get comments for your website
{% disqus_show_comments "YOUR_WEBSITE_SHORTNAME" %}
# get the url for the current object to get the right comments
{% set_disqus_url object.get_absolute_url %}

hope this helps.

user937284
  • 2,454
  • 6
  • 25
  • 29
0

Instead you could try using something like django-disqus which uses simple template tags for loading disqus comments. All it takes is:

# for when using the development server 

{% load disqus_tags %}
{% disqus_dev %}

# for showing all comments of a thread in production

{% load disqus_tags %}
{% disqus_show_comments %}