Linking Django comments with django users
-
27-02-2021 - |
문제
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>