web/code-webpyorg.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

     1 import os
     2 import sqlite3
     3 import web
     4 import fapws._evwsgi as evwsgi
     5 from fapws import base
     8 DBPATH = '/var/www/app/hello/hello.sqlite'
     9 TEMPLATE_PATH = '/var/www/templates/'
    11 urls = (
    12     '/', 'index',
    13     '/(.*)', 'hello',
    14 )
    16 render = web.template.render(TEMPLATE_PATH)
    17 application = web.application(urls, globals()).wsgifunc()
    18 db = web.database(dbn='sqlite', db=DBPATH)
    20 class hello:
    21     def GET(self, username):
    22         users = db.select('hellouser', where="name = '%s'" % username)
    23         isFound = False
    24         for u in users:
    25             if u.name == username:
    26                 isFound = True
    27         if not isFound:
    28             db.query("INSERT INTO hellouser (name) VALUES ('%s')" % username)
    29         return render.hello(username, isFound)
    31 class index:
    32     def GET(self):
    33         return "Hello web.py"
    35 if __name__ == '__main__':
    36     if not os.path.exists(DBPATH):
    37         d = sqlite3.connect(DBPATH)
    38         c = d.cursor()
    39         c.execute("create table hellouser (userid integer primary key autoincrement, \
    40                    name text)")
    41     application = web.application(urls, globals())
    42     application.run()

mercurial