我使用了基于本教程的扩展用户模型。当我提交注册表时,会发生此错误。我在代码中使用 is_active() 和 is_active 时都会显示此错误。如何解决此错误?这是我的代码:模型.pyfrom django.db import modelsfrom django.contrib.auth.models import Userfrom django.db.models.signals import post_savefrom django.dispatch import receiverclass Profile(models.Model): user = models.OneToOneField(User,on_delete=models.CASCADE) full_name = models.CharField(max_length=256, blank=False) codeforces_id = models.CharField(max_length=256, blank=False) Uva_Id = models.CharField(max_length=256, blank=False) #receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: Profile.objects.create(user=instance) #receiver(post_save, sender=User) def save_user_profile(sender, instance, **kwargs): instance.profile.save()视图.pyfrom django.http import HttpResponse from django.shortcuts import render,redirectfrom django.contrib.auth import authenticate,loginfrom django.views import genericfrom django.views.generic import Viewfrom .forms import UserForm,ProfileFormclass UserFormView(View): user_form_class = UserForm profile_form_class= ProfileForm #display a blank form def get(self , request): user_form = self.user_form_class(None) profile_form = self.profile_form_class(None) return render(request, 'website/registration_form.html',{ 'user_form':user_form, 'profile_form':profile_form }) #process form data def post(self, request): user_form = self.user_form_class(request.POST) profile_form = self.profile_form_class(request.POST) user= user_form.save(commit= False) if user_form.is_valid() and profile_form.is_valid(): password= user_form.cleaned_data['password'] username = user_form.cleaned_data['username'] user.set_password(password)
添加回答
举报
0/150
提交
取消