最好有其他web框架基本,不推举小白浏览,
1.视图函数
def login(req):
print(req.method)
# 断定要求方法 注意都是大写的
if req.method == "GET":
# 直接返回页面 这里是应用要求方法来辨别同一个地址的 要求的目标
return render(req, "login.html")
elif req.method == "POST":
# 如果是post要求就获得数据
# print(req.POST) # POST 或GET 获得到的都是一个字典QueryDict类型
# print(req.POST.get("hobby")) # 每一个值都是一个数组类型 直接get得到的是最后一个值
# print(req.POST.getlist("hobby")) # 获得所有值 以列表情势
# 获得用户名和密码:
user = req.POST.get("user")
pwd = req.POST.get("pwd")
# 查询数据库
pool = ZS_POOL.ConnectPool()
res = pool.execute_sql("select *from person where name = %s and password = %s",[user,pwd])
print(res)
if res[0]:
return HttpResponse("login success!")
return HttpResponse("login failed!")
return HttpResponse()
def login(req):
p