在4参数中传递但由Django服务器读取为5

时间:2018-05-30 14:27:44

标签: django

使用模型User

时遇到这种意外错误
TypeError at /user/register
create_user() takes from 2 to 4 positional arguments but 5 were given
Request Method: POST
Request URL:    http://127.0.0.1:8001/user/register
Django Version: 1.11.13
Exception Type: TypeError
Exception Value:    
create_user() takes from 2 to 4 positional arguments but 5 were given

实际上,我确实提供了4个参数而不是5个

def register(request):
    if request.method == "GET":
        form = UserForm()
    if request.method == "POST":
        form = UserForm(request.POST)
        print(vars(form))
        if form.is_valid():
            user = User.objects.create_user(
                      form.cleaned_data['first_name'],
                      form.cleaned_data['last_name'],
                      form.cleaned_data['email'],
                      form.cleaned_data['password'])
            user.save()
        redirect("article/index.html")

和forms.py

class UserForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ['first_name', 'last_name', "email", "password"

问题可能是什么?

0 个答案:

没有答案