类型错误: save()缺少一个必需的位置参数: 'self'

10

这是视图

class RegisterView(View):
def get(self,request):
    register_form = RegisterForm()
    return render(request,'register.html',{'register_form':register_form})
def post(self,request):
    register_form = RegisterForm(request.POST)
    if register_form.is_valid():
        user_name = request.POST.get("email", '')
        pass_word = request.POST.get("password", '')
        user_profile = UserProfile
        user_profile.username = user_name
        user_profile.email = user_name
        user_profile.password = make_password(pass_word)
        user_profile.save()   #error
        send_register_email(user_name,"register")

我想将 user_profile 保存到 mysql 中,但是 user_profile.save() 出现了错误, TypeError: save() missing 1 required positional argument: 'self',我该如何解决?

3
请尝试使用user_profile = UserProfile()替代user_profile = UserProfile,并检查其输出。 - aquaman
1
{btsdaf} - bruno desthuilliers
1个回答

42
您还没有实例化一个UserProfile对象,而是将UserProfile赋值给了user_profile。应该将 user_profile = UserProfile() 改为user_profile = UserProfile。请注意保留所有html标签及其格式。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接