在我的 Django 项目中,我有一个用户身份验证系统。每个用户都有一个用户配置文件:
# Extending main user profile
class UserProfile(models.Model):
# Required
user = models.OneToOneField(User)
# Added fields to main user model
position = models.CharField(max_length=20, null=True, blank=True)
avatar = models.ImageField(upload_to=upload_path_handler, blank=True, default='images/avatar.png')
class Meta:
app_label = 'auth'
# handler -- Create automatically UserProfile foreign key when
# a new user is registered.
def create_user_profile(sender, instance, created, **kwargs):
if created:
# Creating UserProfile
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
好吧,我有一个 context_processor.py,它的主函数返回如下内容:
return {'USER_MEDIA_URL': settings.USER_MEDIA_URL,
'DEBUG': settings.DEBUG,
'SITE_URL': settings.SITE_URL,
'keys_left': keys_left,
'ownRoom': c,
'userThumbnail': request.user.get_profile().avatar,}
我所有的模板都使用“userThumbnail”和“request.user.get_profile().avatar”随机失败,没有任何解释。
模板中返回的错误是:
Unable to load the profile model, check AUTH_PROFILE_MODULE in your project settings
有时我会收到此错误,有时不会。这很烦人。
有什么提示吗?