python django 添加多说评论框

来源:互联网 发布:矩阵分解含义 编辑:程序博客网 时间:2024/05/21 10:15

一口气写了三篇,趁还记得起来吧,一步一个脚印的感觉也不错,当初想个一口气实现很多功能,倒让自己有点不知道从何开始。

纪录下如何去添加多说评论框,首先需要去多说注册个账号:link

注册好了后,多说会提供一段js代码了,如下:

<!-- 多说评论框 start -->                                                                                                                                         <div class="ds-thread" data-thread-key="{{ article.id }}" data-title="{{ article.title }}" data-url="{{ article.get_absolute_url }}"></div><!-- 多说评论框 end --><!-- 多说公共JS代码 start (一个网页只需插入一次) --><script type="text/javascript">var duoshuoQuery = {short_name:"gululu"};    (function() {        var ds = document.createElement('script');        ds.type = 'text/javascript';ds.async = true;        ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';        ds.charset = 'UTF-8';        (document.getElementsByTagName('head')[0]          || document.getElementsByTagName('body')[0]).appendChild(ds);    })();    </script><!-- 多说公共JS代码 end -->

以上要注意的地方主要就是,那三个标签参数和short_name(也就是在多说创建的那个账号)

关于参数article已经很明显,就是需要加评论的那篇文章了.

好了,将多说提供的这段代码保存在templates下面,供别处引用,姑且叫个duoshuo.html的名字。如何引用呢?

{% extends "base.html" %}                                                                                                                                     {% load custom_markdown %} {% block custom_styles %}<link href="/static/blog/css/monokai.css" rel="stylesheet">{% endblock %} {% block title %}{{ article.title }}{% endblock title %}  {% block content %}<h1>{{ article.title }}</h1><div id="main">    {{ article.content | custom_markdown }}</div>{% include "duoshuo.html" %}{% endblock content %}
引用处就在最后两行了,看看效果。



0 0
原创粉丝点击