import time
from bottle import route, run
@route('/')
def index():
return {'status':'online', 'servertime':time.time()}
run(host='localhost', port=8080)
Even dictionaries are allowed. They are converted to json and returned with Content-Type header set to application/json. To disable this feature (and pass dicts to your middleware) you can set bottle.default_app().autojson to False.
出于某种原因,bottle的自动json功能对我不起作用。如果它也不适合你,你可以使用这个装饰器:
也很方便:
return {'status':'online', 'servertime':time.time()}
对我来说非常好。您是否导入了time
?这是有效的:
只需返回一个dict.battle就可以为您处理到JSON的转换。
取自the documentation.
http://bottlepy.org/docs/stable/api.html#the-bottle-class
相关问题 更多 >
编程相关推荐