Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 德扬戈。回复作为评论发布的评论。如何获得评论回复?_Html_Django_Django Models_Django Forms_Django Views - Fatal编程技术网

Html 德扬戈。回复作为评论发布的评论。如何获得评论回复?

Html 德扬戈。回复作为评论发布的评论。如何获得评论回复?,html,django,django-models,django-forms,django-views,Html,Django,Django Models,Django Forms,Django Views,嘿,我是django的新手,我有这个评论和回复功能,问题是我不能回复评论,而是它被作为评论发布。如何在各自的评论下进行回复?这是我的模型和函数 模型 观点 html {%csrf_令牌%} 评论 {%if not post.comment_set.all%} 没有要显示的注释 {%endif%} {post.comment_set.all%} {{comment.timestamp} {{comment.content} {%endif%} {{comment.reply.count} {%

嘿,我是django的新手,我有这个评论和回复功能,问题是我不能回复评论,而是它被作为评论发布。如何在各自的评论下进行回复?这是我的模型和函数

模型

观点

html


{%csrf_令牌%}
评论
{%if not post.comment_set.all%}
没有要显示的注释
{%endif%}
{post.comment_set.all%}

{{comment.timestamp}

{{comment.content}

{%endif%} {{comment.reply.count} {%用于在comment.replements.all%中进行回复}

{{reply.content}

{%endfor%} {%csrf_令牌%} {%endfor%}
我猜表单提交有问题,但我不知道是什么问题。
谢谢,因为回复也是评论。您正在通过以下方式在视图中正确加载注释:

comments = Comment.objects.filter(post=post, reply=None).order_by('-id')
但在模板中,您正在加载评论和回复:

{% for comment in post.comment_set.all %}
尝试:

要加载post评论并选择每个评论的回复,请执行以下操作:

{% for reply in comment.replies.all %}

因为回复也是评论。您正在通过以下方式在视图中正确加载注释:

comments = Comment.objects.filter(post=post, reply=None).order_by('-id')
但在模板中,您正在加载评论和回复:

{% for comment in post.comment_set.all %}
尝试:

要加载post评论并选择每个评论的回复,请执行以下操作:

{% for reply in comment.replies.all %}

这就是我如何轻松解决问题的方法,它在许多方面对我都有帮助

comments=Comment.objects.filter(post=post,reply=None)

{注释%中的注释为%}

{%if comment.reply%}

IF语句将检查注释是否为回复,这有一个父级 如果是,您可以使用{comment.reply.content}和{{comment.reply.timestamp}访问它以打印父级。和{comment.content}打印答复

{%else%}

也就是说,如果评论只是评论而不是回复。 只需打印评论 {{comment.content}


{%endfor%}

这就是我如何轻松解决问题的方法,它在许多方面对我都有帮助

comments=Comment.objects.filter(post=post,reply=None)

{注释%中的注释为%}

{%if comment.reply%}

IF语句将检查注释是否为回复,这有一个父级 如果是,您可以使用{comment.reply.content}和{{comment.reply.timestamp}访问它以打印父级。和{comment.content}打印答复

{%else%}

也就是说,如果评论只是评论而不是回复。 只需打印评论 {{comment.content}


{%endfor%}

你能再解释一下吗?我应该确切地添加到哪里?但是现在有一个问题,它现在没有显示在我的主页中。主页是否使用相同的模板?检查主页中是否也加载了评论。不,我将评论部分作为一个单独的片段,并将其包含在主页和详细页面中。我可以添加comments=Comment.objects.filter(post=post,reply=None)。在详细信息页面中按('-id')排序以显示评论,但不能将其添加到主页。所以有点困惑如何做到这一点,通过在post.comment\u set.all%}中使用
{%作为注释
您可以加载所有注释,然后添加一个过滤器,只显示注释,而不显示回复<代码>{%if comment.reply==None%}您的代码
{%endif%}
。您能再解释一下吗?我应该确切地添加到哪里?但是现在有一个问题,它现在没有显示在我的主页中。主页是否使用相同的模板?检查主页中是否也加载了评论。不,我将评论部分作为一个单独的片段,并将其包含在主页和详细页面中。我可以添加comments=Comment.objects.filter(post=post,reply=None)。在详细信息页面中按('-id')排序以显示评论,但不能将其添加到主页。所以有点困惑如何做到这一点,通过在post.comment\u set.all%}中使用
{%作为注释
您可以加载所有注释,然后添加一个过滤器,只显示注释,而不显示回复<代码>{%if comment.reply==None%}您的代码
{%endif%}
{% for reply in comment.replies.all %}