django应用程序为ajax风格的评论扩展了内置的评论框架。
django-richcomments的Python项目详细描述
Django Richcomments
django应用程序为ajax风格的评论扩展了内置的评论框架。
^ {tt1}$包装django的注释框架,其中存在{{a2}和render_comment_form模板标签,使它们表现为Ajax。
Installation
在python路径中安装或添加django-richcomments。
配置django的注释框架,如here所述。
将richcomments url include添加到项目的urls.py文件:
(r'^richcomments/', include('richcomments.urls')),
确保django-richcomments静态媒体可访问,请参阅managing static files。
Usage
^ tt1}$简单地包装现有的render_comment_list和render_comment_form模板标签,使它们表现为Ajax。因此,当提交评论时,它是通过JavaScript完成的,并且现有的注释列表在没有页面重新加载的情况下更新。您可以按照常规自定义注释列表和表单html。从代码的角度来看,注释的行为与通常完全相同,只是render_comment_form标记生成的表单将通过ajax提交,而render_comment_list生成的注释列表将在提交之后通过ajax更新。
要使richcomments在页面上处于活动状态,需要同时加载jQuery和jQuery form pluginjavascript库。这两个都是作为django-richcomments静态媒体的一部分提供的,并且为您提供了一个快捷模板标记,即:
{% load richcomments %} {% richcomments_static %}
它将呈现以下内容(使用在设置中配置的静态路径):
<script type="text/javascript" src="/static/richcomments/includes/jquery.min.js"></script> <script type="text/javascript" src="/static/richcomments/includes/jquery.form.js"></script>
这里有一个简单的示例,演示如何显示评论列表以及将通过ajax提交和更新的对象的评论表单:
{% load comments richcomments %} <html> <head> {% richcomments_static %} </head> <body> {% render_comment_list for object %} {% render_comment_form for object %} </body> </html>