【发布时间】:2019-07-05 01:25:08
【问题描述】:
我正在向我的 django 应用程序添加 disqus,但无法让它在每个页面上加载新的 cmets 线程。
我已经尝试了所有方法并遵循了文档,其中说明在使用前在 disqus javascript 模板中设置变量。
这是我需要 disqus cmets 的“post_detail.html”:
{% extends 'base.html' %}
{% block content %}
<div class="post-entry">
<h2>{{ post.title }}</h2>
<p>{{ post.body|safe }}</p>
</div>
<div id="disqus_thread"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
var disqus_config = function () {
this.page.url = '{{ request.build_absolute_uri }}'; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = '{{ request.get_full_path }}'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
this.page.title = '{{ post.title }}'
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://bytewise-com.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
{% endblock content %}
根据https://help.disqus.com/developer/javascript-configuration-variables,此函数中的变量设置正确
...
this.page.url = '{{ request.build_absolute_uri }}';
this.page.identifier = '{{ request.get_full_path }}';
...
这是我的浏览器在加载页面时得到的响应,所以我知道变量加载正确。
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
var disqus_config = function () {
this.page.url = 'http://127.0.0.1:8000/post/1/'; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = '/post/1/'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
this.page.title = 'Testing the post function'
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://bytewise-com.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
我也尝试过手动更改变量,以确保它们完全独一无二。还尝试使用 django-disqus 包及其模板标签,但没有结果。
为什么相同的 cmets 仍然出现在我的其他帖子中?
是否与引用“post_detail.html”模板的每个帖子有关?
已经为此工作了几个小时,感谢任何帮助。
【问题讨论】:
标签: python django python-3.x django-templates disqus