You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Post评论用户Profile Name链接不显示求助(附show_more.html代码)

Let's break down what's going wrong here and fix it step by step:

The Core Issues in Your Code

Looking at your template snippet, there are two main problems causing the profile link to not display properly:

  1. Your <a> tag is empty — there's no text inside it for users to see or click on.
  2. You're incorrectly displaying {{ topic.post_owner }} instead of the comment author's name, which is unrelated to the comment itself.

Corrected Template Code

Replace your comment loop with this adjusted version:

{% 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 %}">
      {{ comment.commented_by.username }} <!-- Replace with your profile name field if needed, e.g., .profile_display_name -->
    </a>
  </p>
  {{ comment.comment_body|linebreaks }}
</div>
{% empty %}
<p>There are no comments yet.</p>
{% endfor %}

Key Changes Explained

  • Added visible link text: The <a> tag now includes {{ comment.commented_by.username }} (swap username for your actual profile display name field if you have one, like profile_name). This makes the link clickable and visible to users.
  • Removed irrelevant code: I deleted the {{ topic.post_owner }} line because it was showing the post's owner instead of the comment's author, which was confusing and unnecessary here.
  • Confirmed URL routing: Assuming your show_profile URL pattern accepts a user ID as a parameter, comment.commented_by.id will correctly point to the comment author's profile page. Double-check your urls.py to ensure the parameter name matches (e.g., if the route uses <int:user_id>, the ID pass-through will work as expected).

Quick Troubleshooting Checks

If the link still doesn't work after this fix:

  • Make sure comment.commented_by is a valid User/Profile object (not None). You can add a safety check like {% if comment.commented_by %} around the link to handle edge cases.
  • Verify that the show_profile view correctly fetches the user/profile using the ID passed in the URL.

内容的提问来源于stack exchange,提问作者Lars

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:45:11