0

I encounter such a unexpected error when use model 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

Actually, I do provide 4 arguments rather than 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")

and the forms.py

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

What's the problem it might be?

AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
  • https://stackoverflow.com/questions/37116721/python-typeerror-in-threading-function-takes-x-positional-argument-but-y-were – hansTheFranz May 30 '18 at 14:30
  • 2
    This link might help you: https://stackoverflow.com/questions/49385119/create-user-takes-from-2-to-4-positional-arguments-but-6-were-given – Dasith May 30 '18 at 14:34

0 Answers0