英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论