문제

I am using Django in built comments for allowing users to comment on my posts. I have also customized the app to do the following thing

  • Registered users will see just the text area for comments
  • Unregistered users will see the whole form

Although the whole thing is working fine, I do not understand how can I link the user comment to the user's profile. I want to make the comment name clickable such that it takes you to the user's profile who posted that comment.

However in case of unregistered users I just want to display the name as it. Where and how do I have to make the changes in the comments form, such that it links it with the current user.

도움이 되었습니까?

해결책

Check this answer: How can I include user profile's images/logos on django comments

comment.user or comment.user.get_profile, if you use AUTH_PROFILE_MODULE, should give you the user who posted the comment.

Now you can fetch all the data you need:

<a href="{{ comment.user.get_profile.get_absolute_url }}">
  {{ comment.user.get_profile.firstname }}
</a>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top