开发者

Unable to load profile in django

I am trying to add additional fields to the default User model. I had a look around the internet and done something like this:

Made a new model named UserProfile with the following in /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)

    #开发者_JAVA百科 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()

And added:

 AUTH_PROFILE_MODULE = "newSite.userprofile"

To the settings, I also added "UserProfile" to the INSTALLED_APPS as to run sqlall.

The only problem is when I try the following in the shell:

 >>> from django.contrib.auth.models import User
 >>> user = User.objects.get(username = "user01")
 >>> user.get_profile()

I get the following error:

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

Any help to solve this problem is appreciated!


If you really did create an app caled UserProfile and put the models.py there, then you should put

AUTH_PROFILE_MODULE = "userprofile.userprofile"

into your settings.py file instead.

You should make your UserProfile folder lowercase: userprofile

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜