Django threadedcomments - 如何回复评论?
我正在尝试将 threadedcommetns 集成到我的 Django 应用程序中,但无法理解它的工作原理。这是我的模板的外观(基于 tutorial):
<h3>Comments on This Post:</h3>
{% get_threaded_comment_tree for post as tree %}
{% for comment in tree %}
<div style="margin-left: {{ comment.depth }}em;" class="comment">
{% link_to_profile comment.user %}
{% auto_transform_markup comment %}
</div>
{% endfor %}
<p>Reply to Original:</p>
<form method="POST" action="{% get_comment_url post %}">
{% csrf_token %}
<ul>
{% get_threaded_comment_form as form %}
{{ form.as_ul }}
<li><input type="submit" value="Submit Comment" /></li>
</ul>
</form>
那么,如果这些是线程评论,我如何回复某人已经留下的评论?哪里有表格?我只设法获得回复原始
表单,但有了这个,评论根本就没有线程化。
我将非常感谢你的帮助。
PS 实际上,我不太高兴这个应用程序如何与 django 1.3 一起工作,所以建议一个替代方案也是一个很好的答案。
I am trying to integrate threadedcommetns to my Django app and having trouble in uderstanding how it works. Here is how my template looks (based on example from tutorial):
<h3>Comments on This Post:</h3>
{% get_threaded_comment_tree for post as tree %}
{% for comment in tree %}
<div style="margin-left: {{ comment.depth }}em;" class="comment">
{% link_to_profile comment.user %}
{% auto_transform_markup comment %}
</div>
{% endfor %}
<p>Reply to Original:</p>
<form method="POST" action="{% get_comment_url post %}">
{% csrf_token %}
<ul>
{% get_threaded_comment_form as form %}
{{ form.as_ul }}
<li><input type="submit" value="Submit Comment" /></li>
</ul>
</form>
So, if those are threaded comments, how do I reply to a comment that is already left by someone? Where is the form for that? I only managed to get Reply to Original
form, but with this, comments are not threaded at all.
I would be very grateful for your help.
P.S. Actually,I am not very happy how this app is working with django 1.3, so suggesting an alternative would be a great answer too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
似乎 django threadedcommetns 这里不是很受欢迎:)
我找到了一个很棒的库: django-mptt
这是我的教程,描述如何使用 django-mptt 在 django 中实现线程注释: http: //codeblogging.net/blogs/1/3/
Seems like django threadedcommetns are not very popular here :)
I've found a great library: django-mptt
Here is my tutorial that describes how to implement threaded comments in django using django-mptt: http://codeblogging.net/blogs/1/3/
表单中有一个“id_parent”div,将值更改为父级的id。
使用 jQuery 是这样的:
There is a "id_parent" div in the form, change the value to the parent's id.
with jQuery something like this:
你对原文的回复看起来不错。
假设您想保留每条评论的回复表单并将其保留为线索。
在这里,我们呈现评论树并在每个评论下方保留一个表单,允许回复该特定评论。此表单的帖子 URL 设置为
{% get_comment_url post comment %}
。除了您在问题中描述的所有内容之外,这是我们所做的唯一更改。该模板标签的所有内容是发布帖子,但也为回复设置父级。回复的父级是您要回复的{{comment}}
。因此,如果您想要“回复原文”,请使用
{% get_comment_url post %}
。如果您想回复特定评论,请使用
{% get_comment_url post comment %}
。Your reply to original looks good.
Say you want to keep reply form for every comment and keep it as threaded.
Here we render the comment tree and keep a form beneath each comment which allows reply for that particular comment. The post url for this form is set as
{% get_comment_url post comment %}
. This is the only change we made apart from all that you described in the question. All this template tag says is that do a post but also set a parent for the reply. And the parent for the reply is the{{comment}}
for which you are replying.So, if you want "Reply for original", you use
{% get_comment_url post %}
.And if you want to reply for a particular comment, you use
{% get_comment_url post comment %}
.明智的一句话:如果您是 Django(或编码)新手,并且您正在构建一些简单的用于演示或学习目的的东西,请不要使用线程注释。这是比其价值更多的工作。自己构建一个简单的评论模型即可。话虽如此,这就是我如何获得回复的方法,与 @akshar 的回复非常相似。
列表.html:
A word to the wise: if you're new to Django (or coding) and if you're building something simple for demo or learning purposes - don't use threaded comments. It's more work than it's worth. Just build a simple a comments model yourself. With that said, here's how I got the replies to work, very similar to @akshar's response.
list.html: