在所有具有唯一性的页面上显示相同的注释页面.url以及页码.ids

2024-06-08 14:07:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在向我的django应用程序添加discus,但无法让它在每个页面上加载新的评论线程。在

我已经尝试了所有的方法,并遵循了文档中的说明,在使用之前要在discus javascript模板中设置变量。在

这是我的帖子_详细信息.html“这需要Discus的评论:

{% 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正确设置的

^{pr2}$

下面是我的浏览器对加载页面的响应,因此我知道变量加载正确。在

 /**
  *  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-discus包及其模板标记,但没有结果。在

为什么同样的评论仍然出现在我的其他帖子上?在

这和每个引用“post”的帖子有关吗_详细信息.html'模板?在

已经为此工作了几个小时了,任何帮助都将不胜感激。在


Tags: httpsdivcomtitlevarpagescriptfunction
1条回答
网友
1楼 · 发布于 2024-06-08 14:07:54

我查看了discus管理页面,它显示了http://127.0.0.1:8000/post作为线程的url,编辑它会给我一个关于无效url格式的错误。 我觉得很奇怪,所以我删除了网站和评论。在

将变量更改为:

this.page.url = '{{ request.build_absolute_uri }}.html'

无论出于什么原因,discus似乎更同意这一点,不确定这是否是有意的,但它似乎正在运作良好。在

相关问题 更多 >