7
votes

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?

1
Could you try user_profile = UserProfile() instead of user_profile = UserProfile and check its output. - aquaman
Unrelated, but using a form to sanitize user inputs and not using the sanitized data is asking for trouble. Use your form's .cleaned_data to retrieve the email and password instead of getting them from request.POST. Or use a ModelForm instead... - bruno desthuilliers

1 Answers

33
votes

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

user_profile = UserProfile

should be

user_profile = UserProfile()