<html><head><title>输入账号密码</title></head> <body> <form action="/deal_request" method="get"> 请输入账号:<input type="text" name="usr" ><br> 请输入密码:<input type="password" name="psd"><br> <input type="submit" value="提交" /> </form> </body></html> |
<html><head><title>Welcome</title></head> <body> <h1>登录成功!</h1><br> <h1>欢迎你: ① </h1><br> </body></html> |
编写的 Python 程序如下:
from flask import Flask, render_template, request
import sqlite3
② = Flask(_name_)
@app.route('/')
def input():
return render_template('input.html')
@app.route('/deal_request', methods = ['GET'])
def deal_request():
get_usr = request.args.get('usr')
get_psd = request.args.get('psd')
if check(get_usr, get_psd):
return render_template('succes.html', name=get_usr)
else:
return '用户名或密码错误!'
def check(name, psd):
db=sqlite3.connect('login.db')
cur= ③ #创建游标对象
cur.execute('select * from users')
data=cur.fetchall()
for rec in data: #比对用户名与密码
if rec[ 1]==name and rec[2]==psd:
return True
else:
return False
if _name_ == '_main_':
app.run(host=' 127.0.0. 1 ', port=5000, debug=False)
请完成下列题目:
②③