Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在模板中获取额外的用户配置文件?
访问配置文件时,我这样做:
{{ request.user.get_profile.x }}
...但我有一个名为 UserReferralProfile 的附加 OneToOne 配置文件。如何从模板访问它?
您只需执行以下操作:
{{ request.user.userreferralprofile.y }}
或者,如果您指定了related_name,
related_name
class UserReferralProfile(models.Model): x = models.OneToOneField(User, related_name='referal') y = models.CharField()
在模板中,
{{ request.user.referal.y }}