使用步骤: 1、在settings文件中的INSTALLED_APPS中加入'django.contrib,comments',。 2、执行命令,manage.py syncdb,创建数据表。 3、urls.py中 (r'^comments/',include('django.contrib.comments.urls')),。 4、编辑templates文档。  
{% load comments %}
{% get_comment_list for articles.Articles a.id as comment_list %}
{% for comment in comment_list %}

评论人:{{comment.user.username}}{{comment.user.email}}|评论时间:{{comment.submit_date|date:"Y-m-d H:i"}} |ip地址:{{comment.ip_address}}

{{comment.comment}}
{% endfor %} {% get_comment_form for articles.Articles a.id as form %}
{% csrf_token %}{{form.object_pk}}{{form.content_type}}{{form.timestamp}}{{form.security_hash}}

{% load comments %} 是所有要用到comments组件的模板都需要加进入标签。 a.id是上面文章的id,没有规范写。 <input type="hidden" name="next" value="/articles/36/" />实现评论成功后的跳转,功能还没实现。 还有一个功能没实现,就是非登陆用户的评论限制。 具体参考官网“the built-in comment models”
<table> <tr> <th>作者:{{a.user.username}}</th><th>时间:{{a.datetime|date:'Y-m-d H:i'}}</th><th>IP:{{a.ip}}</th></tr> <tr><td><b>{{a.title}}</b></td></tr> <tr><td>{{a.content}}</td></tr> </table> {% load comments %} {% get_comment_list for articles.Articles a.id as comment_list %} {% for comment in comment_list %} <div> <p>评论人:<b>{{comment.user.username}}{{comment.user.email}}</b>|评论时间:{{comment.submit_date|date:"Y-m-d H:i"}}|ip地址:{{comment.ip_address}}</p> {{comment.comment}} </div> {% endfor %} {% get_comment_form for articles.Articles a.id as form %} <form action={% comment_form_target %} method="post"> {% csrf_token %}{{form.object_pk}}{{form.content_type}}{{form.timestamp}}{{form.security_hash}} <p><label for="id_comment">评论:</label></p> <p><textarea name="comment"></textarea></p> <input type="hidden" name="next" value="/articles/36/" /> <p><input name="post" value="发表" type="submit" /></p> </form>

上一篇:
下一篇:

相关文章:

Categories: 博客记录

2 Responses so far.

  1. slider 说:

    lz,a.id这里到底怎么写,我还不清楚

  2. 0X55AA 说:

    当时我是用一个list_detail.object_detail返回写的,template_object_name='a'

Leave a Reply