一个用于 Django 的评论应用程序
Pinax is an open-source platform built on the Django Web Framework. It is an ecosystem of reusable Django apps, themes, and starter project templates. This collection can be found at http://pinaxproject.com.
Where you can find what you need:
pinax-comments is a comments app for Django.
| Django / Python | 3.6 | 3.7 | 3.8 |
|---|---|---|---|
| 2.2 | * | * | * |
| 3.0 | * | * | * |
To install pinax-comments:
$ pip install pinax-commentsAdd pinax.comments to your INSTALLED_APPS setting:
INSTALLED_APPS = [
# other apps
"pinax.comments",
]Add pinax.comments.urls to your project urlpatterns:
urlpatterns = [
# other urls
url(r"^comments/", include("pinax.comments.urls", namespace="pinax_comments"))
]Common usage involves wiring up template tags as seen in this example, which presents
a form for adding a new comment on wall_user, as well as showing existing comments.
Three template tags are used here: comment_target, which returns a URL for posting
a comment on wall_user; comment_form, which returns a comment form for
wall_user; and comments, which returns all comments on wall_user.
{% comments wall_user as wall_comments %}
{% for comment in wall_comments %}
{% endfor %}
can_delete_commentReturns True if user can delete comment.
{% if comment|can_delete_comment:user %}can_edit_commentReturns True if user can edit comment.
{% if comment|can_edit_comment:user %}comment_countReturns number of comments on obj.
Usage:
{% comment_count obj %}or
{% comment_count obj as var %}comment_formReturns a comment form for obj. Checks context user to determine
if the comment should be from an authenticated or anonymous user.
Usage:
{% comment_form obj as comment_form %}comment_targetReturns the URL for posting a comment on obj
{% comment_target obj %}or
{% comment_target obj as var %}commentsReturns iterable of comments on obj as context variable var.
{% comments obj as var %}Both signals provide two keyword arguments: comment, the relevant Comment instance, and request.
commentedSent when a comment is added.
comment_updatedSent when a comment is updated.
load_can_delete(self, user, comment)Override this method to specify if user can delete comment. By default only comment authors can edit comments.
load_can_edit(self, user, comment)Override this method to specify if user can edit comment. By default, Django superusers and comment authors can delete comments.
This example hooks.py overrides default load_can_edit() with a silly alternative:
# myapp.hooks.py
from pinax.comments.hooks import CommentsDefaultHookSet
class CommentsHookSet(CommentsDefaultHookSet):
def load_can_edit(self, user, comment):
return user.username in ["funk", "wagnalls"]Used to provide your own custom hookset methods, as described above. Value is a dotted path to your own hookset class:
PINAX_COMMENTS_HOOKSET = "myapp.hooks.CommentsHookSet"context_instance kwargContributing information can be found in the Pinax community health file repo.
In order to foster a kind, inclusive, and harassment-free community, the Pinax Project has a Code of Conduct. We ask you to treat everyone as a smart human programmer that shares an interest in Python, Django, and Pinax with you.
For updates and news regarding the Pinax Project, please follow us on Twitter @pinaxproject and check out our Pinax Project blog.
Copyright (c) 2012-present James Tauber and contributors under the MIT license.
暂无开放 Issues,或尚未同步最近议题。