Django 1-1 关系如何
profile = UserProfile.objects.get(....)
我尝试做的 - 是获取当前登录用户的个人资料。我应该在括号里写什么?
profile = UserProfile.objects.get(....)
what i try to do - is to get profile for the currently logged in user. What should i put in the brackets?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您遵循此处描述的模式:
http ://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
您应该能够使用以下内容:
Assuming you are following the pattern described here:
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
You should be able to use the following:
普通人,没必要这么严厉……有些人实际上不知道灰色轮廓勾号是你应该按的。
但如果它是一个
OneToOne
字段,您应该能够执行request.user.userprofile
http://docs.djangoproject.com/ en/dev/topics/db/queries/#one-to-one-relationships
Comon guys, no need to be so harsh... Some people actually don't know that the grey outline checkmark is what you're supposed to press.
But if it's a
OneToOne
field, you should be able to dorequest.user.userprofile
http://docs.djangoproject.com/en/dev/topics/db/queries/#one-to-one-relationships