结构图如下:
主程序如下:
#coding=utf-8
import sys,hashlib
reload(sys)
sys.setdefaultencoding('utf8')
import web
web.config.debug = False
from web import form
db = web.database(dbn='postgres', user='postgres', pw='redhat', db='lockey')
#数据库连接
render = web.template.render('templates/')
#定义渲染模板位置
urls = (
'/', 'index',
'/register','register',
'/login', 'login',
'/logout','logout'
)
#定义url
app = web.application(urls, globals())
session = web.session.Session(app, web.session.DiskStore('sessions'), initializer={
'username': None})
myform = form.Form(
form.Textbox("用户名",
form.notnull,
form.regexp('[A-Za-z0-9\-]+', 'Must be alpha or digit!'),
form.Validator('Must be more than 5 characters!', lambda y:len(y)>5)),
form.Textbox("姓名",
form.notnull,
form.regexp('\d+', 'Must be a digit'),
form.Validator('Must be more than 5', lambda x:int(x)>