我已经在本地环境中安装了一个工作的夹层(带有pybb)。pybb有一个抽象的Profile类来定义一些用户属性,并且还附带了一个Profile类,以防您还没有使用。
一切都在工作,除了注册过程,最终创建一个用户,但导致以下追溯:
http://pastebin.com/MFuBpc2A我认为pybbMiddleware可能是问题所在。(如何创建两个配置文件?)
class PybbMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
try:
# Here we try to load profile, but can get error
# if user created during syncdb but profile model
# under south control. (Like pybb.Profile).
profile = request.user.get_profile()
except ObjectDoesNotExist:
# Ok, we should create new profile for this user
# and grant permissions for add posts
user_saved(request.user, created=True)
profile = request.user.get_profile()
language = translation.get_language_from_request(request)
if not profile.language:
profile.language = language
profile.save()
if profile.language and profile.language != language:
request.session['django_language'] = profile.language
translation.activate(profile.language)
request.LANGUAGE_CODE = translation.get_language()
pybb的signals.py中的user_saved():
def user_saved(instance, created, **kwargs):
if not created:
return
try:
add_post_permission = Permission.objects.get_by_natural_key('add_post', 'pybb', 'post')
add_topic_permission = Permission.objects.get_by_natural_key('add_topic', 'pybb', 'topic')
except ObjectDoesNotExist:
return
instance.user_permissions.add(add_post_permission, add_topic_permission)
instance.save()
if settings.AUTH_PROFILE_MODULE == 'pybb.Profile':
from models import Profile
Profile(user=instance).save()
在上面我有另一个user_saved()在accounts/models.py:
@receiver(post_save, sender=User)
def user_saved(sender=None, instance=None, **kwargs):
Profile.objects.get_or_create(**{str(user_field): instance})
是否同时调用两个配置文件,从而创建两个配置文件?
谢谢你的帮助!
我怀疑你正在使用夹层。并在settings.py中设置AUTH_PROFILE_MODULE。models中的代码设置一个信号,以便在保存用户模型时生成一个概要文件。在使用tastype创建用户和配置文件时,我实际上遇到了同样的问题。