Django get_profile()方法不适用于扩展用户模型 [英] Django get_profile() method not working on extended User model

查看:396
本文介绍了Django get_profile()方法不适用于扩展用户模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 user_profile 的应用程序,如下所示:

I have a model in an app named user_profile like so:

from django.db import models
from django.contrib.auth.models import User

class UserProfile(models.Model):
    user = models.OneToOneField(User)

    def __unicode__(self):
        return self.user.username

在我的设置中:

AUTH_PROFILE_MODULE = 'user_profile.UserProfile'

但是如果我尝试:

u = UserProfile.objects.get(pk=1)
p = u.get_profile()

我得到以下错误:

AttributeError: 'UserProfile' object has no attribute 'get_profile'

我在这里缺少什么?

任何帮助将不胜感激。 >

Any help would be much appreciated.

推荐答案

呃,你试图获取一个UserProfile的用户配置文件。我希望你的意思是得到一个用户,然后调用 get_profile()

Er, you're trying to get the user profile of a UserProfile. I expect you mean to get a User, then call get_profile() on that.

这篇关于Django get_profile()方法不适用于扩展用户模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆