Profile matching query does not exist.

huangapple go评论71阅读模式
英文:

Profile matching query does not exist

问题

我遇到了"Profile matching query does not exist"的错误,以下是我的代码enter image description here

英文:

Hi have getting error of Profile matching query does not exist and here is my codeenter image description here

Hi have getting error of Profile matching query does not exist and here is my code[enter image description here]

答案1

得分: 0

请查看用户对象。

你也可以尝试这样做:

user = User.objects.get(username=request.user.username)
profile = user.profile.filter().first()

然后在你的模型类中,将related_field="profile"添加到用户外键字段。

这种方法称为数据库关系。

或者你可以这样做:

user = User.objects.get(username=request.user.username)
profile = Profile.objects.get(user_id=user.id)

这将给你想要的结果。

英文:

Check the User Object.

You can as well try this:

user = User.objects.get(username=request.user.username)
profile = user.profile.filter().first()

Then in your model class, add related_field="profile" to the user ForiegnKey field.

This Approach is called Database Relationship.

Or You can do it this way.

user = User.objects.get(username=request.user.username)
profile = Profile.objects.get(user_id=user.id)

This will give you what you want.

huangapple
  • 本文由 发表于 2023年4月6日 23:49:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951431.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定