2013-07-23 23 views
1

的disqus評論框我用django創建了一個博客,並試圖使用disqus評論。我遇到了類似的問題,我在其他問題中看到過,當我發表評論時(在單個入口頁面上),它們都顯示在主頁面上的一個條目下。Django-disqus:關於

主要的問題是,在博客的主頁上,我有多個條目,我只能得到一個disqus評論框出現在一個條目上。當我查看源代碼時,其他博客條目的javascript變量似乎正確顯示,因此我不確定爲什麼評論框不會在其他博客條目下呈現。

我處於開發模式,所以我不知道這是否有所作爲...我也是一個小菜一碟。

這是我爲disqus javascript獲得的每個條目的源代碼......任何人都可以幫我弄清楚爲什麼我無法獲得評論框來呈現?

<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> 
+0

我剛剛注意到的一件奇怪的事情是,當頁面加載時,我會在每個博客條目下簡短地看到「由disqus支持的評論」,但當頁面加載完成後,它就會消失。 – LVNGD

回答

1

Disqus旨在每頁加載one Disqus郵箱。 Disqus使用頁面URL作爲唯一標識符,並且只有一個Disqus嵌入可以與單個URL相關聯。如果在頁面的源代碼中存在多個Disqus嵌入,則只會加載一個嵌入。

有辦法reload the disqus embed有不同的標識符:

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

然而,這種方法仍然只每頁都會有一個嵌入使用。

1

這已解決,但我想通過使用django-disqus來顯示不同的方法。最後一行是爲您提供特定頁面/對象的正確評論的那一行。

安裝django-disqus並在您的模板中使用它。

pip install django-disqus 

添加disqus你INSTALLED_APPS,把你的disqus的API密鑰設置:

settings.py

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

DISQUS_API_KEY = 'YOUR_SECRET_API_KEY' 
DISQUS_WEBSITE_SHORTNAME = 'YOUR_WEBSITE_SHORTNAME' 

在模板中使用disqus模板標籤:

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