标签:src password short 提交 models exce except return enc
from django.shortcuts import render,redirect,render_to_response from django.http import HttpResponse from .models import * from hashlib import sha1 # Create your views here. def index(request): return render(request,‘index.html‘) def register(request): return render(request,‘register.html‘) def adduser(requset): uname = requset.POST[‘user‘] upwd = requset.POST[‘pwd‘] ucpwd = requset.POST[‘cpwd‘] uemail = requset.POST[‘email‘] #密码加密 #构造对象 s1=sha1() s1.update(upwd.encode("utf-8")) upwd2 = s1.hexdigest() if upwd != ucpwd: return redirect(‘/register/‘) try: usr = userinfo() usr.username=uname usr.password=upwd2 usr.email=uemail usr.save() #userinfo.objects.get_or_create(username=uname,password=upwd) msg=‘user create success!‘ all = userinfo.objects.all() return render(requset, ‘info.html‘, {‘msg‘: msg, ‘all‘: all}) except Exception as e: #return render(requset,‘info.html‘,{‘msg‘:e,‘all‘:all}) return HttpResponse({‘<html>数据重复了<a href="/"><h2>返回</h2></a></html>‘},e)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Register</title> </head> <body> <form action="/adduser/" method="POST"> {% csrf_token %} 账号: <input type="text" name="user"><br> 密码: <input type="password" name="pwd"><br> 确认密码:<input type="password" name="cpwd"><br> 邮箱: <input type="email" name="email"><br> <input type="submit" value="提交"> </form> </body> </html>
标签:src password short 提交 models exce except return enc
原文地址:https://www.cnblogs.com/phyger/p/9114440.html