【问题标题】:getting this TypeError: is_valid() missing 1 required positional argument: 'self'得到这个 TypeError: is_valid() missing 1 required positional argument: 'self'
【发布时间】:2020-05-29 16:56:25
【问题描述】:

我收到类型错误: is_valid() 缺少 1 个必需的位置参数:'self'

请纠正我做错的地方

def register(request):
registered = False

if request.method == "POST":
    user_form = UserForm(request.POST)
    profile_form = UserProfileInfoForm(request.POST, request.FILES)

    if user_form.is_valid() and UserProfileInfoForm.is_valid():
        user = user_form.save()
        user.set_password(user.password)
        user.save()

        profile = profile_form.save(commit=False)
        profile.user = user

        if 'profile_pic' in request.FILES:
            profile.profile_pic = request.FILES['profile_pic']

        profile.save()
        registered = True

    else:
        print(user_form.errors, profile_form.errors)

else:
    user_form = UserForm()
    profile_form = UserProfileInfoForm()

return render(request, 'basic_app/registration.html',
              {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})

【问题讨论】:

  • 你在类上调用is_valid,而不是在对象上。将UserProfileInfoForm.is_valid() 替换为profile_form.is_valid()

标签: javascript python html jquery django


【解决方案1】:

你忘了参加instance类。但是,你使用了类。所以,这样做:

if user_form.is_valid() and profile_form.is_valid():

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    • 2022-01-06
    • 2016-05-09
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多