django-blog-zinnia集成多说评论框

django-blog-zinnia基于django.contrib.comments内置了一套评论功能,此外还有zinnia_threaded_comments插件支持评论回复,但均不支持社会化评论。

多说评论框是一款社会化评论插件,支持用新浪微博、腾讯QQ、人人、豆瓣多帐号登录,帮助网站进行社会化媒体优化,可以为你的独立博客快速地集成日志评论功能,实际效果见页面底部的评论框。

下面简述一下django-blog-zinnia集成多说评论框的步骤。

1. 在base.html模板中添加duoshuo的公用js代码:


{% block script %}
{{block.super}}
<script type="text/javascript">
var duoshuoQuery = {short_name:"在此填写多说注册的网站短名称"};
  (function() {
    var ds = document.createElement('script');
    ds.type = 'text/javascript';ds.async = true;
    ds.src = 'http://static.duoshuo.com/embed.js';
    ds.charset = 'UTF-8';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ds);
  })();
</script>
{% endblock %}

2. 设置日志的多说评论数,新增或修改_entry_detail.html(位于zinnia_threaded_comments/templates/zinnia/或者zinnia/templates/zinnia/目录下),代码如下:


{% extends "zinnia/_entry_detail_base.html" %}
{% load comments i18n zinnia_tags %}
{% block entry-discussions %}
<p class="entry-discussions">
  <span class="glyphicon glyphicon-comment"></span> <strong>{% trans "Discussions" %}</strong> :
  <a href="{{ object.get_absolute_url }}#comments"
	 title="{% blocktrans with object=object.title %}Comments on {{ object }}{% endblocktrans %}">
	<span class="ds-thread-count" data-thread-key="{{object.pk}}" data-count-type="comments">暂无评论</span>
  </a>
</p>
{% endblock entry-discussions %}

3. 删除评论表单,修改/zinnia/templates/comments/zinnia/entry/或者/zinnia_threaded_comments/templates/comments/zinnia/entry/目录下的form.html,注释表单html

4. 修改/zinnia_threaded_comments/templates/zinnia/entry_detail_base.html,除去trackbacks和pingbacks模块,并更换多说评论框,代码如下:


{% extends "zinnia:zinnia/entry_detail_base.html" %}
{% load static i18n comments zinnia_tags mptt_tags %}

{% block link %}
  {{ block.super }}
  <link rel="stylesheet" type="text/css" href="{% static "zinnia_threaded_comments/css/comment-reply.css" %}" />
{% endblock link %}

{% block script %}
  {{ block.super }}
  {% if object.comments_are_open %}<script type="text/javascript" src="{% static "zinnia_threaded_comments/js/comment-reply.js" %}"></script>{% endif %}
{% endblock %}


{% block entry-widgets %}
<aside class="entry-widgets" role="complementary">
  {% block entry-related-entries %}
  {% with entry_related=object.related_published %}
  {% if entry_related %}
  <div class="entry-related panel panel-default">
    <div class="panel-heading">
      {% trans "Related entries" %}
    </div>
    <ul class="list-group">
      {% for entry in entry_related %}
      <li class="list-group-item">
	<a href="{{ entry.get_absolute_url }}" title="{{ entry.title }}" rel="bookmark">{{ entry.title }}</a>
      </li>
      {% endfor %}
    </ul>
  </div>
  {% endif %}
  {% endwith %}
  {% endblock entry-related-entries %}
  {% block entry-similar-entries %}
  <div class="entry-similar panel panel-default">
    <div class="panel-heading">
      {% trans "Similar entries" %}
    </div>
    {% get_similar_entries %}
  </div>
  {% endblock entry-similar-entries %}
  {% block entry-previous-next-entries %}
  <div class="entry-prev-next">
    <ul class="pager">
      {% with next_entry=object.next_entry %}
      {% if next_entry %}
      <li class="next">
        <a href="{{ next_entry.get_absolute_url }}" title="{{ next_entry.title }}" rel="next">
          {{ next_entry.title }} →
        </a>
      </li>
      {% endif %}
      {% endwith %}
      {% with previous_entry=object.previous_entry %}
      {% if previous_entry %}
      <li class="previous">
        <a href="{{ previous_entry.get_absolute_url }}" title="{{ previous_entry.title }}" rel="prev">
          ← {{ previous_entry.title }}
        </a>
      </li>
      {% endif %}
      {% endwith %}
    </ul>
  </div>
  {% endblock entry-previous-next-entries %}
</aside>
{% endblock entry-widgets %}

{% block entry-comments %}
<a name="comments" id="comments" ></a>
<div class="ds-thread" data-thread-key="{{entry.pk}}" data-title="{{entry.title}}" data-url="http://{{ request.get_host }}{{ request.get_full_path }}"></div>
{% endblock entry-comments %}

{% block entry-pingbacks %}
{% endblock entry-pingbacks %}

{% block entry-trackbacks %}
{% endblock entry-trackbacks %}

{% block admin-tools %}
{% if perms.zinnia.change_entry %}
<li class="list-group-item">
  <a href="{% url 'admin:zinnia_entry_change' object.pk %}" title="{% trans "Edit the entry" %}">
    <span class="glyphicon glyphicon-edit"></span>
    {% trans "Edit the entry" %}
  </a>
</li>
{% endif %}
{% endblock admin-tools %}

 

本文链接:http://bookshadow.com/weblog/2014/06/04/django-blog-zinnia-add-duoshuo/
请尊重作者的劳动成果,转载请注明出处!书影博客保留对文章的所有权利。

如果您喜欢这篇博文,欢迎您捐赠书影博客: ,查看支付宝二维码