跳转到主要内容

一个简单而灵活的线程式评论系统。

项目描述

django-threadedcomments

threadedcomments 是一个 Django 应用,允许简单地创建一个线程式评论系统。评论者可以对原始条目进行回复,也可以对其他评论进行回复。

该应用基于 django_comments 构建,这使得它可以通过其他模块轻松扩展。

安装

通过 pip 安装此包

pip install django-threadedcomments

建议在虚拟环境中安装模块。

配置

将以下内容添加到 settings.py

INSTALLED_APPS += (
    'threadedcomments',
    'django_comments',
    'django.contrib.sites',
)

COMMENTS_APP = 'threadedcomments'

通过将 threadedcomments 应用放置在 django.contrib.comments 应用之上,占位符 comments/list.html 模板将自动被线程视图替换。

确保在 urls.py 中配置了 django_comments

urlpatterns += patterns('',
    url(r'^articles/comments/', include('django_comments.urls')),
)

提供一个模板,用于显示对象(例如文章或博客条目)的评论

{% load threadedcomments_tags %}

...

<h2>Comments for {{ object.title }}:</h2>

{% render_comment_list for object %}
{% render_comment_form for object %}

模板设计

当然,最好是在您的项目中编写自己的 comments/list.html 版本,或者使用 comments/app/list.htmlcomments/app/model/list.html 覆盖之一。

确保同时覆盖 comments/base.html,以便使用您的网站设计显示 django_comments 的其他视图。由于这些页面依赖于网站的定制设计,django_comments 的其他模板也故意非常简单(例如 comments/posted.html)。

请参阅提供的 example 应用以获取基本配置,包括一个基于 JavaScript 的回复表单,该表单将移动到访客回复的评论。

模板标签

threadedcomments_tags 库是 comments 库的替换品,后者用于纯评论。标签是向前兼容的;它们支持与 django_comments 提供的相同的语法,并添加了一些额外的参数。

获取评论数

{% get_comment_count for [object] as [varname] %}
{% get_comment_count for [object] as [varname] root_only %}

{% get_comment_count for [app].[model] [id] as [varname] %}
{% get_comment_count for [app].[model] [id] as [varname] root_only %}

获取评论列表

{% get_comment_list for [object] as [varname] %}
{% get_comment_list for [object] as [varname] flat %}
{% get_comment_list for [object] as [varname] root_only %}

渲染评论列表

{% render_comment_list for [object] %}
{% render_comment_list for [object] root_only %}

{% render_comment_list for [app].[model] [id] %}
{% render_comment_list for [app].[model] [id] root_only %}

获取评论表单

{% get_comment_form for [object] as [varname] %}
{% get_comment_form for [object] as [varname] with [parent_id] %}
{% get_comment_form for [app].[model] [id] as [varname] %}
{% get_comment_form for [app].[model] [id] as [varname] with [parent_id] %}

渲染评论表单

{% render_comment_form for [object] %}
{% render_comment_form for [object] with [parent_id] %}
{% render_comment_form for [app].[model] [id] %}
{% render_comment_form for [app].[model] [id] with [parent_id] %}

渲染整个树

{% for comment in comment_list|fill_tree|annotate_tree %}
    {% ifchanged comment.parent_id %}{% else %}</li>{% endifchanged %}
    {% if not comment.open and not comment.close %}</li>{% endif %}
    {% if comment.open %}<ul>{% endif %}

    <li id="c{{ comment.id }}">
        ...
    {% for close in comment.close %}</li></ul>{% endfor %}
{% endfor %}

对于分页,需要 fill_tree 过滤器,它确保包含第一个评论的父级。

annotate_tree 过滤器将 openclose 属性添加到评论中。

扩展模块

该应用基于标准的 django_comments 框架,该框架支持各种信号和模板覆盖以自定义评论。

要自定义 django-threadedcomments,请覆盖适当的模板或包含提供缺失功能的应用程序。例如,前端编辑支持是有意为之的。它属于监管领域,需要知道“谁可以做什么”的政策。这应该是一个独立的应用程序,而不应该在这个应用程序中,因为它专注于线程。同样适用于社交媒体登录、评论订阅、垃圾邮件保护和 Ajax 发布。

请注意,标准框架也支持监管、标记和 RSS 源。更多文档可以在以下位置找到:

一些值得关注的模块包括:

这些模块可以进一步增强评论系统。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

django-threadedcomments-2.0.tar.gz (17.9 kB 查看散列)

上传时间:

构建分发

django_threadedcomments-2.0-py2.py3-none-any.whl (21.3 kB 查看散列)

上传时间: Python 2 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面