return "Welcome!" # Validating URL Parameter @route("/validate/:i/:f/:csv") @validate(i=int, f=float, csv=lambda x: map(int, x.strip().split(","))) def validate_test(i, f, csv): return "Int: %d, Float:%f, List:%s" % (i, f, repr(csv)) # Templates @route("/template/test") def template_test(): return template("howto", title="Template Test", items=[1, 2, 3, "fly"]) # Database @route("/db/counter") def db_counter_test(): if "hits" not in db.counter: db.counter.hits = 0 print "fresh", db.counter.keys() db["counter"]["hits"] += 1 return "Total hits in this page: %d!" % db.counter.hits import fly fly.DEBUG = True run(server=fly.PasteServer, host="localhost", port=8080)
from fly import route, run, request, response, send_file, abort @route('/') def hello_world(): return 'Hello World!' @route('/hello/:name') def hello_name(name): return 'Hello %s!' % name @route('/hello', method='POST') def hello_post(): name = request.POST['name'] return 'Hello %s!' % name @route('/static/:filename#.*#') def static_file(filename): send_file(filename, root='/path/to/static/files/') if __name__=='__main__': run(host='127.0.0.1', port=8000)