piku/examples/python/main.py

28 wiersze
838 B
Python
Czysty Zwykły widok Historia

2016-03-29 19:31:12 +00:00
import os
2016-05-03 19:46:19 +00:00
from bottle import default_app, route, request, view, static_file, run
2016-03-29 19:31:12 +00:00
2016-05-03 19:46:19 +00:00
@route("/")
@view("base")
2016-03-29 19:31:12 +00:00
def default():
2016-05-03 19:46:19 +00:00
result = {}
table = ['<table class="u-full-width"><tbody>']
2016-05-03 21:17:44 +00:00
for k, v in sorted(os.environ.iteritems()):
2016-03-29 19:31:12 +00:00
table.append('<tr><th>%s</th><td>%s</td></tr>' % (k, v))
2016-05-03 19:46:19 +00:00
table.append('</tbody></table>')
result['sys_data'] = '\n'.join(table)
table = ['<table class="u-full-width"><tbody>']
2016-05-03 21:17:44 +00:00
for k, v in sorted(dict(request.environ).iteritems()):
2016-05-03 18:51:56 +00:00
table.append('<tr><th>%s</th><td>%s</td></tr>' % (k, v))
2016-05-03 19:46:19 +00:00
table.append('</tbody></table>')
result['req_data'] = '\n'.join(table)
return result
@route("/<path:path>")
def static(path):
return static_file(path, root="static")
app = default_app()
2016-03-29 20:41:03 +00:00
if __name__ == '__main__':
2016-05-03 19:46:19 +00:00
run(port=int(os.environ.get("PORT",8080)))