User.save() 在登录时得到一个意外的关键字参数 'update_fields'

User.save() got an unexpected keyword argument 'update_fields' while login

我正在开发一个博客网站,我正在编辑个人资料信息并在个人资料模板中进行了一些更改,在对模板进行了更改之后,登录时突然出现此错误,它在编辑模板之前工作正常,现在注册也是不工作,我无法使用管理面板登录

User.save() 得到了意外的关键字参数 'update_fields'
Models.py

class User(AbstractUser):
    profile_image =  models.ImageField(("Profile Image"), 
                        upload_to='ProfileImage', 
                        max_length=None,
                        blank = True,null = True)
    profile = models.TextField(("Profile"),blank = True)

    def save(self):
        super().save()  

        img = Image.open(self.profile_image.path)

        if img.height > 400 or img.width > 400:
            new_img = (400, 400)
            img.thumbnail(new_img)
            img.save(self.profile_image.path)

    def __str__(self):
        return self.username'

Views.py

class userLogin(View):
     def get(self,request):
          return render(request,"account/login.html")

     def post(self,request):
          if request.method == "POST":
               username = request.POST['username']
               password = request.POST['password']
               #try:
               user = authenticate(username=username, password=password)
               if user is not None:
                    login(request, user)
                    messages.info(request, f"You are now logged in as {username}")
                    return redirect('/')
               else:
                    messages.error(request, "Invalid username or password.")


          return render(request,'account/login.html')

我不知道突然发生了什么,除了模板之外我没有改变任何东西

您应该在保存方法中接受 *args**kwargs.save(…) method [Django-doc] 接受多个参数,因此您应该 而不是 修改签名。否则,Django 逻辑的某些部分会假设它们可以使用这些参数调用 .save(…) 方法,因此无法调用。

因此您可以接受任意数量的位置参数和命名参数,并将它们传递给超级调用:

class User(AbstractUser):
    # …
    
    def save(self<strong>, *args, **kwargs</strong>):
        img = Image.open(self.profile_image.path)
        if img.height > 400 or img.width > 400:
            new_img = (400, 400)
            img.thumbnail(new_img)
            img.save(self.profile_image.path)
        super().save(<strong>*args, **kwargs</strong>)