Django threadedcomments - 如何回复评论?

发布于 2024-11-06 05:39:45 字数 1162 浏览 2 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏九 2024-11-13 05:39:45

似乎 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/

乖乖哒 2024-11-13 05:39:45

表单中有一个“id_parent”div,将值更改为父级的id。

使用 jQuery 是这样的:

$('#commentForm').find("#id_parent").attr("value", divid);

There is a "id_parent" div in the form, change the value to the parent's id.

with jQuery something like this:

$('#commentForm').find("#id_parent").attr("value", divid);
丘比特射中我 2024-11-13 05:39:45

你对原文的回复看起来不错。

<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>

假设您想保留每条评论的回复表单并将其保留为线索。

<div class="bulk">
    {% get_threaded_comment_tree for post as tree %}
        {% for comment in tree %}
            <div style="margin-left:{{comment.depth}}em;">
                {{comment}}
                Reply to this comment
                <form action="{% get_comment_url post comment %}" method="POST">
                    <ul>
                        {% get_threaded_comment_form as form %}
                        {{ form.as_ul }}
                        <li><input type="submit" value="Submit Reply" /></li>
                    </ul>
                </form>
            </div>
        {% endfor %}
</div>

在这里,我们呈现评论树并在每个评论下方保留一个表单,允许回复该特定评论。此表单的帖子 URL 设置为 {% get_comment_url post comment %}。除了您在问题中描述的所有内容之外,这是我们所做的唯一更改。该模板标签的所有内容是发布帖子,但也为回复设置父级。回复的父级是您要回复的 {{comment}}

因此,如果您想要“回复原文”,请使用 {% get_comment_url post %}

如果您想回复特定评论,请使用 {% get_comment_url post comment %}

Your reply to original looks good.

<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>

Say you want to keep reply form for every comment and keep it as threaded.

<div class="bulk">
    {% get_threaded_comment_tree for post as tree %}
        {% for comment in tree %}
            <div style="margin-left:{{comment.depth}}em;">
                {{comment}}
                Reply to this comment
                <form action="{% get_comment_url post comment %}" method="POST">
                    <ul>
                        {% get_threaded_comment_form as form %}
                        {{ form.as_ul }}
                        <li><input type="submit" value="Submit Reply" /></li>
                    </ul>
                </form>
            </div>
        {% endfor %}
</div>

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 %}.

箹锭⒈辈孓 2024-11-13 05:39:45

明智的一句话:如果您是 Django(或编码)新手,并且您正在构建一些简单的用于演示或学习目的的东西,请不要使用线程注释。这是比其价值更多的工作。自己构建一个简单的评论模型即可。话虽如此,这就是我如何获得回复的方法,与 @akshar 的回复非常相似。

列表.html:

{% load threadedcomments_tags %}
<div id="comments">
    {% for comment in comment_list|fill_tree|annotate_tree %}
        {% if comment.open %}
            <ul>
        {% else %}
            </li>
        {% endif %}
        <li id="c{{ comment.id }}">{# c## is used by the absolute URL of the Comment model, so keep that as it is. #}
            <dl class="comment">
                <dt>
                    {{ comment.submit_date }} - {{ comment.name }}, ID: {{ comment.id }} <i>To test parent:{{ comment.parent_id }}</i>
                </dt>
                <dd>
                    {{ comment.comment|linebreaks }}
                    {% render_comment_form for object with comment.id %}
                </dd>
            </dl>
            {% for close in comment.close %}</li></ul>{% endfor %}
    {% endfor %}
</div>

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:

{% load threadedcomments_tags %}
<div id="comments">
    {% for comment in comment_list|fill_tree|annotate_tree %}
        {% if comment.open %}
            <ul>
        {% else %}
            </li>
        {% endif %}
        <li id="c{{ comment.id }}">{# c## is used by the absolute URL of the Comment model, so keep that as it is. #}
            <dl class="comment">
                <dt>
                    {{ comment.submit_date }} - {{ comment.name }}, ID: {{ comment.id }} <i>To test parent:{{ comment.parent_id }}</i>
                </dt>
                <dd>
                    {{ comment.comment|linebreaks }}
                    {% render_comment_form for object with comment.id %}
                </dd>
            </dl>
            {% for close in comment.close %}</li></ul>{% endfor %}
    {% endfor %}
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文