Python 为什么我尝试使用Django用户配置文件时出错了?
我正在尝试创建一个用户配置文件对象;my models.py目前的内容如下:Python 为什么我尝试使用Django用户配置文件时出错了?,python,django,django-models,Python,Django,Django Models,我正在尝试创建一个用户配置文件对象;my models.py目前的内容如下: from django.contrib.auth.models import User from django.db.models.signals import post_save from django.db import models class UserProfile(models.Model): name = models.TextField() scratchpad = models.Tex
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.db import models
class UserProfile(models.Model):
name = models.TextField()
scratchpad = models.TextField()
user = models.ForeignKey(User, unique = True)
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user = instance)
post_save.connect(create_user_profile, sender = User)
在my settings.py的顶部,我有:
AUTH_PROFILE_MODULE = 'models.UserProfile'
我得到一个错误屏幕:
SiteProfileNotAvailable at /
Unable to load the profile model, check AUTH_PROFILE_MODULE in your project settings
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.3.1
Exception Type: SiteProfileNotAvailable
Exception Value:
Unable to load the profile model, check AUTH_PROFILE_MODULE in your project settings
Exception Location: /usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/contrib/auth/models.py in get_profile, line 380
Python Executable: /usr/local/bin/python
Python Version: 2.7.0
Python Path:
['/Users/jonathan/pim',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/pip-0.8.1-py2.7.egg',
'/usr/local/Cellar/python/2.7/lib/python27.zip',
'/usr/local/Cellar/python/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/local/Cellar/python/2.7/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7/lib/python2.7/lib-old',
'/usr/local/Cellar/python/2.7/lib/python2.7/lib-dynload',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/PIL',
'/usr/local/lib/python2.7/site-packages',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Server time: Tue, 14 Feb 2012 11:48:23 -0600
models.py文件位于/Users/jonathan/pim中
我做错了什么?如何设置才能使models.py中的UserProfile注册为用户配置文件
谢谢
--编辑--
关于站点和包名,我在项目根目录/Users/jonathan/pim的models.py中定义了UserProfile。是否需要将其移动到项目中的应用程序?目前我没有被切掉的应用程序
--第二次编辑--
柏油球在我想你需要
AUTH_PROFILE_MODULE = 'app.UserProfile'
(注意app.Model
,而不是models.UserProfile
)
其中,
app
是您的应用程序的名称,从外观上看,pim
在已安装的应用程序设置中丢失了当我将其设置为“pim.UserProfile”时,会出现相同的外观错误。@JonathanHayward:您的站点/应用程序树中的包名称到底是什么?请更新问题。如果我设置“user=models.OneToOneField(user)”,它的行为也相同。