2013-02-13 34 views
1

好吧,我知道这是一个愚蠢的问题,但我被封锁,我不知道该怎么做。Django - 自定义用户模型的用户创建导致内部错误

我已搜查谷歌和计算器,但没有找到任何答案: 我尝试这样做:

我的模型如下:

class UserProfile(models.Model): 
    user = models.OneToOneField(User) 

    quota = models.IntegerField(null = True) 


def create_user_profile(sender, instance, created, **kwargs): 
    if created: 
     UserProfile.objects.create(user=instance) 

post_save.connect(create_user_profile, sender=User) 

我的用户注册视图如下:

def register(request): 
    if request.method == 'POST': # If the form has been submitted... 
     form = RegistrationForm(request.POST) # A form bound to the POST data 
     if form.is_valid(): # All validation rules pass 
      # Process the data in form.cleaned_data 
      cd = form.cleaned_data 

      #Then we create the user 
      user = User.objects.create_user(cd['username'],cd["email"],cd["password1"]) 

      user.get_profil().quota = 20 

      user.save() 

      return HttpResponseRedirect('') 

    else: 
     form = RegistrationForm() # An unbound form 

    return render(request, 'registration_form.html', {'form': form,}) 

一个启动的InternalError是该行:

user = User.objects.create_user(cd['username'],cd["email"],cd["password1"]) 

和错误是:

InternalError at /register/ 

current transaction is aborted, commands ignored until end of transaction block 

谢谢寻求帮助

回答

3
user = User.objects.create_user(username=form.cleaned_data['username'], 
           password=form.cleaned_data['password'], 
           email=form.cleaned_data['email']) 
user.is_active = True 
user.save() 
+0

非常感谢,不知道我怎么错过了 – ltbesh 2013-02-13 16:31:04

+0

欢迎光临,,,,,,,, – catherine 2013-02-13 16:31:51

相关问题