Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

django

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?

like image 969
kerberos Avatar asked Oct 24 '17 09:10

kerberos


1 Answers

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

user_profile = UserProfile

should be

user_profile = UserProfile()

like image 161
Anbarasan Avatar answered Nov 18 '22 09:11

Anbarasan