组卷题库 > 高中信息技术试卷库
试题详情
利用Flask和Sqlite模块,编写相应的Python程序与网页代码,来模拟用户登录验证过程。功能是:运行Python程序,启动浏览器并输入相应网址,在网页中输入用户名、密码,与数据库中的数据进行比对,若正确则在浏览器中显示成功信息,否则显示“用户名或密码错误!”。存储用户名、密码的数据表中共有三个字段,依次表示序号、用户名、密码。input.html网页与success.html网页内容如下:

<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)

请完成下列题目:

知识点
参考答案
采纳过本试题的试卷
教育网站链接