为什么我尝试使用Django用户资料时出错?
我正在尝试创建一个用户个人资料对象;我的 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.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)
在我的 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 中定义了 UserProfile 在 models.py 里。这需要移动到项目中的某个应用程序里吗?目前我没有将应用程序分开。
--第二次编辑--
。2 个回答
0
看起来,pim
没有被添加到 INSTALLED_APPS 设置中。
2
我觉得你需要这个
AUTH_PROFILE_MODULE = 'app.UserProfile'
(注意是 app.Model
,而不是 models.UserProfile
)
这里的 app
是你应用的名字