你好我是python和django的新手我需要一个获取当前用户配置文件的视图我知道我应该使用来自User的get_profile但我不知道如何使用它.我读了django文件,它没有帮助我.这是我从doc中找到的:
from django.contrib.auth.models import User
profile=request.user.get_profile()
Run Code Online (Sandbox Code Playgroud) 我在一个名为的应用程序中有一个模型user_profile:
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
Run Code Online (Sandbox Code Playgroud)
在我的设置中:
AUTH_PROFILE_MODULE = 'user_profile.UserProfile'
Run Code Online (Sandbox Code Playgroud)
但如果我尝试:
u = UserProfile.objects.get(pk=1)
p = u.get_profile()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
AttributeError: 'UserProfile' object has no attribute 'get_profile'
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
任何帮助将非常感激.