简体   繁体   English

Django 1.9 错误 - 'User' 对象没有属性 'profile'

[英]Django 1.9 error - 'User' object has no attribute 'profile'

So I recently added an optional user profile model that is linked to a user via a OneToOneField like so:所以我最近添加了一个可选的用户配置文件模型,它通过 OneToOneField 链接到用户,如下所示:

class UserProfile(models.Model): # Creating class
    user = models.OneToOneField(User, on_delete=models.CASCADE)

This worked fine, and my current UserProfile models were intact both before and after I added in this field to link the profile to a user.这工作正常,并且我当前的 UserProfile 模型在我添加此字段以将配置文件链接到用户之前和之后都完好无损。

The problem comes when I log in on the website as a valid user, after submitting the log in form comes an error:当我以有效用户身份登录网站时出现问题,提交登录表单后出现错误:

AttributeError at /login/ /login/ 处的属性错误

'User' object has no attribute 'profile' “用户”对象没有“个人资料”属性

I have searched through my files for anything along the lines of ' User.profile ', and similar queries, however I can't seem to find anything that would allow me to properly log in as a user.我已经在我的文件中搜索了“ User.profile ”和类似查询中的任何内容,但是我似乎找不到任何可以让我以用户身份正确登录的内容。

I wasn't sure what other code to post here, and didn't want to spam this question with potentially unnecessary code so tell me if there's anything more specific (views.py, models.py, forms.py, etc) that will be needed to solve this sort of problem, or if you know of any possible solutions.我不确定要在此处发布哪些其他代码,并且不想用可能不必要的代码向此问题发送垃圾邮件,因此请告诉我是否有更具体的内容(views.py、models.py、forms.py 等)需要解决此类问题,或者如果您知道任何可能的解决方案。

Thank you谢谢

您尚未在该一对一字段上设置任何 related_name 属性,因此反向访问器将被称为userprofile而不是profile

确保您的应用在 settins.py INSTALLED_APPS 中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django-扩展用户配置文件错误用户没有属性用户配置文件 - Django - extend user profile error user has no attribute userprofile Django Rest Framework为自定义用户错误创建配置文件:'tuple'对象没有属性'_meta' - Django Rest Framework creating profile for custom user error:'tuple' object has no attribute '_meta' Django错误:“ WSGIRequest”对象没有属性“ user” - Django Error : 'WSGIRequest' object has no attribute 'user' 显示用户个人资料出现错误:“ AnonymousUser”对象没有属性“ _meta” - Display User Profile getting ERROR: 'AnonymousUser' object has no attribute '_meta' Django AttributeError at /accounts/profile/ 'User' object has no attribute 'get' while update profile - Django AttributeError at /accounts/profile/ 'User' object has no attribute 'get' while update profile django 1.9 AttributeError:'unicode'对象没有属性'_meta' - django 1.9 AttributeError: 'unicode' object has no attribute '_meta' Django 1.9在列表中查找属性等于某个值的对象 - Django 1.9 Find object in list that has attribute equal to some value Django1.9:'function' 对象没有属性 '_meta' - Django1.9: 'function' object has no attribute '_meta' AttributeError:'str'对象没有属性'regex'django 1.9 - AttributeError: 'str' object has no attribute 'regex' django 1.9 在 django 中注册新用户后自动创建配置文件时出现问题,错误显示此“Manager”对象没有“created”属性 - Have problem to auto create profile after register new user in django the error show this 'Manager' object has no attribute 'created'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM