2
我想添加額外的字段到默認的用戶模型。我不得不在互聯網一看,做這樣的事情:無法加載在Django中的配置文件
做了題爲用戶配置與新模式/UserProfile/models.py如下:
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
# This is the only required field
user = models.ForeignKey(User, unique=True)
# The rest is completely up to you...
favorite_band = models.CharField(max_length=100, blank=True)
favorite_cheese = models.CharField(max_length=100, blank=True)
lucky_number = models.IntegerField()
並補充說:
AUTH_PROFILE_MODULE = "newSite.userprofile"
對於設置,我還將「UserProfile」添加到INSTALLED_APPS以運行sqlall。
唯一的問題是,當我嘗試在shell下:
>>> from django.contrib.auth.models import User
>>> user = User.objects.get(username = "user01")
>>> user.get_profile()
我得到以下錯誤:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 367,in get_profile
raise SiteProfileNotAvailable('Unable to load the profile '
SiteProfileNotAvailable: Unable to load the profile model, check AUTH_PROFILE_MODULE in your project settings
任何有助於解決這個問題表示讚賞!
謝謝你,我改變了文件夾名稱以小寫字符和它工作得很好! – pyBite42 2010-09-21 01:40:17
然而,第二部分是不區分大小寫的。 – 2012-04-20 01:30:03