Post评论用户Profile Name链接不显示求助(附show_more.html代码)
Fixing the Invisible Profile Name Link in Comment Section
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:
- Your
<a>tag is empty — there's no text inside it for users to see or click on. - 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 }}(swapusernamefor your actual profile display name field if you have one, likeprofile_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_profileURL pattern accepts a user ID as a parameter,comment.commented_by.idwill correctly point to the comment author's profile page. Double-check yoururls.pyto 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_byis a valid User/Profile object (notNone). You can add a safety check like{% if comment.commented_by %}around the link to handle edge cases. - Verify that the
show_profileview correctly fetches the user/profile using the ID passed in the URL.
内容的提问来源于stack exchange,提问作者Lars
相关产品推荐
相关产品推荐

