1
votes

I've created a blog with django and am trying to use disqus comments. I am having a similar problem that I have seen in other questions in that when I post comments to any entries(on single entry pages) they all show up on the main page under one entry.

The main problem is that on the main page of the blog, where I have multiple entries, I can only get one disqus comment box to show up on one entry. When I look at the source code the javascript variables for the other blog entries seem to be showing up correctly so I'm not sure why the comment boxes won't render under the other blog entries.

I'm in development mode so I'm not sure if that makes a difference...I'm also a noob at all of this.

This is the source code I get for the disqus javascript for each entry...can anyone help me figure out why I can't get the comment box to render?

<div id="disqus_thread"></div>
<script type="text/javascript">
/* <![CDATA[ */

    var disqus_shortname = 'whometaxi';
    var disqus_developer = "1";
    var disqus_identifier = "3";
    var disqus_title = "Third";

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>

<div id="disqus_thread"></div>
<script type="text/javascript">
/* <![CDATA[ */

    var disqus_shortname = 'whometaxi';
    var disqus_developer = "1";
    var disqus_identifier = "1";
    var disqus_title = "First post";

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>

<script type="text/javascript">
/* <![CDATA[ */

    var disqus_shortname = 'whometaxi';
    var disqus_developer = "1";
    var disqus_identifier = "2";
    var disqus_title = "Second!";

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
2
One weird thing I just noticed is that as the page loads I briefly see "comments powered by disqus" under each blog entry but then it disappears when the page has finished loading.LVNGD

2 Answers

1
votes

Disqus is designed to load one Disqus postbox per page. Disqus uses the page URL as a unique identifier and only one Disqus embed can be associated with a single URL. If more than one Disqus embed is present in the source code of a page, only one embed will load.

There is a way to reload the disqus embed with different identifiers:

  DISQUS.reset({
  reload: true,
  config: function () {  
    this.page.identifier = "newidentifier";  
    this.page.url = "http://example.com/#!newthread";
  }
});

However, this method is still only used with one embed per page.

1
votes

This is solved but I'd like to show a different approach by using django-disqus. The last line is the one that gets you the right comments for the specific page/object.

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 %}