/ Published in: Python
**work in progress**
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/python # -*- coding: utf-8 -*- import os import bottle as web # http://bottle.paws.de/page/docs DEV=True web.debug(DEV) @web.route("/static/:path") def static(path): web.send_file(path,root="static") @web.route('/:name#.*#') def index(name): name = name or "unknown" web.response.content_type = 'text/html; charset=utf-8' web.response.COOKIES['kiki'] = name return """hello %(name)s <a href='/do/show?a=1&a=2'>show</a>""" % locals() @web.route('/do/:cmd?') def cmd(cmd): if cmd=="show": yield "<li>cookies : %s</li>"% str(web.request.COOKIES) yield "<li>get : %s</li>"% str(web.request.GET) yield "<li>post : %s</li>"% str(web.request.POST) else: web.redirect("/") #don't work with yield now ;-( @web.route('/.*') def fallback(): yield "my 404" #~ web.abort(404, "Not Found") @web.error(500) # don't work for me ?!? def fallback500(err): return "my error:"+str(err) def main(useGae=False): if useGae: from google.appengine.ext.webapp import util util.run_wsgi_app(web.default_app()) else: web.run(reloader=DEV) if __name__=="__main__": main()
URL: http://bottle.paws.de/page/docs