查看多个表单未保存(表单上缺少 1 个位置参数)

View with multiple forms not saving (missing 1 positional argument on form)

我已经为 Django-Registration-Redux 设置了覆盖以保存在下面的附加模型 UserProfile 上:

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    tel_number = models.CharField(max_length=20, null = True)

这是使用以下形式设置的:

class UserProfileRegistrationForm(RegistrationFormUniqueEmail):
    tel_number = forms.CharField()

和regbackend.py:

from registration.backends.default.views import RegistrationView
from .forms import UserProfileRegistrationForm
from .models import UserProfile

class MyRegistrationView(RegistrationView):

    form_class = UserProfileRegistrationForm

    def register(self, request, form_class):
        new_user = super(MyRegistrationView, self).register(request, form_class)
        user_profile = UserProfile()
        user_profile.user = new_user
        user_profile.tel_number = form_class.cleaned_data['tel_number']
        user_profile.save()
        return user_profile

然而,即使视图加载正确并且我可以填写它,每次保存时我都会收到以下错误:

register() missing 1 required positional argument: 'form_class'

我认为这是传递错误?

我在这里快速检查了代码:

https://github.com/macropin/django-registration/blob/master/registration/backends/default/views.py

那个Django-Registration-Redux好像是在RegistrationView中实现的,注册方法是这样的:

def register(self, form):
   #code

尝试删除请求,它应该可以工作,就像这样。

def register(self, form_class):
   new_user = super(MyRegistrationView, self).register(form_class)
   #code