[英]Recursive comment system in django
I have a comment system for my website and I pass all the comments with the relevant post but when I loop through the comments and show each comment it's children it shows the children after it as independent comments.我的网站有一个评论系统,我将所有评论与相关帖子一起传递,但是当我循环浏览评论并显示每条评论是子评论时,它会将其后的孩子显示为独立评论。
{% load custom_tags %}
{% for comment in page_obj %}
<div class="comments">
<h6>
<a href="{% url 'main:creator' comment.publisher.id %}">
{{comment.publisher.name}}
</a>
</h6>
<span>{{ comment.created_on}}</span>
<div>
{{comment.text}}
<br>
</div>
{% if comment.children %}
<ul style="margin-right: 5%;">
{% include "post/comment.html" with page_obj=comment.children %}
</ul>
{% endif %}
</div>
{% endfor %}
You confused margin-right
and margin-left
.您混淆
margin-right
和margin-left
。 Setting margin-right: 5%;
设置
margin-right: 5%;
wouldn't add the right margin which wouldn't move the child comments.不会添加不会移动子评论的右边距。 You need to replace
margin-right: 5%;
你需要替换
margin-right: 5%;
with margin-left: 5%;
margin-left: 5%;
. .
The other possibility is related to peculiarities of parent div
.另一种可能性与父
div
的特性有关。 5%
might not works in some situations. 5%
在某些情况下可能不起作用。 You can try to replace it with something like 50px
in case the previous option doesn't works.您可以尝试用
50px
之类的东西替换它,以防之前的选项不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.