这是观点
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()缺少1个必需的位置参数:' self' ,我该如何解决?
答案 0 :(得分:15)
您尚未实例化UserProfile
的对象,而是将UserProfile
分配给user_profile
user_profile = UserProfile
应该是
user_profile = UserProfile()