简体   繁体   中英

TypeError: save() missing 1 required positional argument: 'self'

this is views

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")

I want to save user_profile to mysql,But user_profile.save() has an error, TypeError: save() missing 1 required positional argument: 'self' ,How should I solve it?

you have not instantiated an object of UserProfile , instead you are assigning UserProfile to user_profile

user_profile = UserProfile

should be

user_profile = UserProfile()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM