尝试用webpy写了个很山寨的登录页面

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#author:zeal
#只是判断了下有没有cookie,没有就算没登录.
import web
 
# For debugging use only
web.internalerror = web.debugerror
render = web.template.render('template/')
urls = (
    '/', 'index',
    '/logout', 'logout',
)

class index:
    def GET(self):
        cookie = web.cookies()
        islogin = False
        if cookie :
            islogin =True
        print 'islogin=',islogin
        return  render.index(islogin)
    def POST(self):
        cache = False
        cookie = web.cookies()
        #user accout and password
        userdb = [('test','test'),
                          ('a','a'),
                  ]
        i = web.input(name = "guest",password ="guest")
        print i
        print 'webdata.usn=',str(i['usn'])
        print 'webdata.pwd=',str(i['pwd'])
        usn = str(i['usn'])
        pwd = str(i['pwd'])
        result = (usn,pwd) in userdb
        if result :
            web.setcookie('name', usn,3600)
            web.setcookie('password', pwd,3600)
            web.seeother('/')
        else:
            login = 'wrong user name or password'
            raise web.seeother('/')

class logout:
    def GET(self):
        web.setcookie('name', '', 'Mon, 01-Jan-2001 00:00:00 GMT')
        web.setcookie('password', '', 'Mon, 01-Jan-2001 00:00:00 GMT')
        raise web.seeother('/')
		
if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

你可能感兴趣的:(Web,python,cache)