将 Django 评论与 django 用户链接
我在内置评论中使用 Django,以允许用户对我的帖子发表评论。我还自定义了该应用程序以执行以下操作
- 注册用户将仅看到评论文本区域
- 未注册用户将看到整个表单
虽然整个事情工作正常,但我不明白如何将用户评论链接到用户的评论轮廓。我想让评论名称可点击,以便将您带到发布该评论的用户的个人资料。
但是,对于未注册的用户,我只想显示名称。我必须在哪里以及如何在评论表单中进行更改,以便将其与当前用户链接。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查这个答案:如何我在 django 评论中包含用户个人资料的图像/徽标
comment.user
或comment.user.get_profile
,如果您使用AUTH_PROFILE_MODULE
,应该为您提供发表评论的用户。现在您可以获取所需的所有数据:
Check this answer: How can I include user profile's images/logos on django comments
comment.user
orcomment.user.get_profile
, if you useAUTH_PROFILE_MODULE
, should give you the user who posted the comment.Now you can fetch all the data you need: