예제 #1
0
 def post(self, request):  # 注册页面视图
     # 接收参数
     data = request.POST
     # 表单验证合法
     form = RegisterModelForm(data)
     if form.is_valid():
         # 操作数据库
         clened_data = form.cleaned_data
         # 创建一个用户
         user = Users()
         user.phone = clened_data.get('phone')
         user.password = set_password(clened_data.get('password'))
         user.save()
         return redirect('user:登录')
     # 错误
     else:
         return render(request, 'user/reg.html', context={'form': form})
예제 #2
0
 def post(self, request):
     # 完成用户信息的注册
     # 接收参数
     data = request.POST
     # 验证参数合法性 表单验证
     form = RegisterModelForm(data)
     if form.is_valid():
         # 获取清洗后的数据
         cleaned_data = form.cleaned_data
         # 保存数据库
         user = Users()
         user.phone = cleaned_data.get('phone')
         user.password = set_password(cleaned_data.get('password'))
         user.save()
         return redirect('user:登录')
     else:
         return render(request, 'user/reg.html', context={'form': form})