-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.py
68 lines (58 loc) · 1.75 KB
/
code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
import web
import os
import sys
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
import apiinstances
from sqlalchemy.orm import scoped_session, sessionmaker
from model.dbmodel import engine
#urls 定向配置
urls = (
"/mytest","mytest",
"/", "Index",
)
#模板定向
render = web.template.render(os.path.abspath(os.path.dirname(__file__)) + '/templates/', base="base")
#域名获取
realhome = web.ctx.get("realhome", "/lsgoapi")
#接口索引页面
class Index():
def GET(self):
web.header('Content-Type', 'text/html')
#b = dict(zip(urls[0::2], urls[1::2]))
#for item in b:
# yield """<a href="%s" >%s</a><br>""" % (item, b[item].lower())
return render.index(urls[0::2], urls[0::2], realhome)
#测试页面 显示web 服用器各种参数
class mytest():
count = 0
def GET(self):
return web.ctx.__dict__
#输出http头全局配置为 application/json 勾子
def setheader_json():
web.header('Content-Type', 'application/json')
#get a new sqlalchemy session for the web.ctx.orm
def load_sqla(handler):
web.ctx.orm = scoped_session(sessionmaker(engine))
try:
return handler()
except web.HTTPError:
web.ctx.orm.commit()
raise
except:
web.ctx.orm.rollback()
# debug only
#return '{"code": 11, "ermsg": u"系统错误"}'
#raise
finally:
web.ctx.orm.commit()
web.ctx.orm.close()
app = web.application(urls, globals())
#输出http头全局配置为 application/json 勾子
app.add_processor(web.loadhook(setheader_json))
app.add_processor(load_sqla)
#使用服务器使用 mode_wsgi 运行
application = app.wsgifunc()
web.config.debug = True
if __name__ == "__main__":
app.run()