web/code-fapws3.wsgi

Sat Jun 20 20:44:03 2009 +0900

author
hattori@www.hexacosa.net
date
Sat Jun 20 20:44:03 2009 +0900
changeset 6
c6da061b21c4
permissions
-rwxr-xr-x

profiling for web application

hattori@4 1 import web
hattori@4 2 import fapws._evwsgi as evwsgi
hattori@4 3 from fapws import base
hattori@4 4
hattori@4 5
hattori@4 6 DBPATH = '/var/www/app/hello/hello.sqlite'
hattori@4 7 TEMPLATE_PATH = '/var/www/templates/'
hattori@4 8
hattori@4 9 urls = (
hattori@4 10 '/', 'index',
hattori@4 11 '/(.*)', 'hello',
hattori@4 12 )
hattori@4 13
hattori@4 14 render = web.template.render(TEMPLATE_PATH)
hattori@4 15 application = web.application(urls, globals()).wsgifunc()
hattori@4 16 db = web.database(dbn='sqlite', db=DBPATH)
hattori@4 17
hattori@4 18 class hello:
hattori@4 19 def GET(self, username):
hattori@4 20 users = db.select('hellouser', where="name = '%s'" % username)
hattori@4 21 isFound = False
hattori@4 22 for u in users:
hattori@4 23 if u.name == username:
hattori@4 24 isFound = True
hattori@4 25 if not isFound:
hattori@4 26 db.query("INSERT INTO hellouser (name) VALUES ('%s')" % username)
hattori@4 27 return render.hello(username, isFound)
hattori@4 28
hattori@4 29 class index:
hattori@4 30 def GET(self):
hattori@4 31 return "Hello web.py"
hattori@4 32
hattori@4 33 if __name__ == '__main__':
hattori@4 34 application = web.application(urls, globals()).wsgifunc()
hattori@4 35 evwsgi.start("0.0.0.0", 8080)
hattori@4 36 evwsgi.set_base_module(base)
hattori@4 37 evwsgi.wsgi_cb(("", application))
hattori@4 38 evwsgi.run()
hattori@4 39

mercurial