其中会员注册子页面如图b所示。存储会员信息的users表中共3个字段,依次保存序号、用户名和密码,如图c所示。会员注册时需满足以下条件:①用户名不重复;②密码长度大于5。服务器端部分代码如下。
from flask import Flask , render_template , request
import sqlite3
def check(name ,pwd):
conn= sqlite3 .connect( " account .db ")
cur=conn .cursor()
cur . execute( " select * from users where name= ’%s ’"%name)
val=cur .fetchall()
flag=True
if len(val)==0 and :
sql= "insert into users(name , password) values(' %s' , '%s ') "%(name , pwd)
cur .execute(sql)
conn .commit()
else:
flag=False
cur .close()
conn .close()
return flag
app=Flask(name_)
@app .route( "/reg ")
def reg() :
name=request . args .get( "xm ")
pwd=request .args .get( "psd ")
if :
return "注册成功! "
else:
return "请重新注册! "
#其它代码略
if _name_== "_main_ " :
app .run (host= " 192 . 168 . 1 . 10 " , port= 80 , debug=True)