【问题标题】:Profile Name link is not showing of user , which is commented on Post个人资料名称链接未显示用户,已在帖子上发表评论
【发布时间】:2020-12-09 10:44:53
【问题描述】:

show_more.html(这是Post的模板,看cmets并添加cmets)

   <hr>
{% for comment in comments %}
  <div class="comment">
    <p class="info">
      {{ comment.created_at|naturaltime }}
      Commented by :-  <a href="{% url 'mains:show_profile' comment.commented_by.id %}"></a> # I think the problem is in this line. BUT i've tried everything.
        {{ topic.post_owner }}
    </p>
    {{ comment.comment_body|linebreaks }}
  </div>
{% empty %}
  <p>There are no comments yet.</p>
{% endfor %}

我已经尝试了一切,但没有任何效果,请帮助我。非常感谢您的帮助。

【问题讨论】:

  • 请将 urls.py 也添加到问题中

标签: html django django-templates


【解决方案1】:

您需要将 comment.commented_by.id 传递给 URL 'user_id'

的 kwarg
<a href="{% url 'mains:show_profile' user_id=comment.commented_by.id %}"> {{ comment.commented_by }} </a>

【讨论】:

  • 先生,它在评论后显示为空白:- 它没有显示名称
【解决方案2】:

请尝试

comment.commented_by

而不是

comment.commented_by.id.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 2017-05-23
    • 2022-01-10
    • 2013-12-18
    • 1970-01-01
    相关资源
    最近更新 更多