def insert(request): '''添加数据''' try: ob = Users() ob.username = request.POST['username'] ob.name = request.POST['name'] ob.password = request.POST['password'] ob.repassword = request.POST['repassword'] if ob.password != ob.repassword: context = {"info": "两次密码不符"} else: # 获取密码并md5 import hashlib m = hashlib.md5() m.update(bytes(ob.password, encoding="utf8")) ob.password = m.hexdigest() # 调用hexdigest方法对密码进行加密 ob.sex = request.POST['sex'] ob.address = request.POST['address'] ob.code = request.POST['code'] ob.phone = request.POST['phone'] ob.email = request.POST['email'] ob.state = 1 ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 格式化时间 ob.save() context = {'info': '添加成功'} except Exception as err: context = {"info": '添加失败'} return render(request, 'myadmin/info.html', context)
def vipadd(request): ''' 写入注册信息界面 ''' try: ob = Users() ob.username = request.POST['username'] ob.password = request.POST['password'] ob.repassword = request.POST['repassword'] if ob.password != ob.repassword: context = {"info": "两次密码不符"} else: #获取密码并md5 import hashlib m = hashlib.md5() m.update(bytes(ob.password, encoding="utf8")) ob.password = m.hexdigest() #调用hexdigest方法对密码进行加密 ob.save() context = {'info': '注册成功,请登陆!'} return render(request, 'web/login.html', context) except Exception as err: context = {"info": '注册失败,该账户已存在!'} return render(request, 'web/vip/register.html', context)