Created
July 2, 2013 18:28
-
-
Save yszou/5911800 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
if os.access('bottle.py.cache', os.F_OK): | |
with open('bottle.py.cache', 'r') as f: | |
code = f.read() | |
else: | |
import urllib2 | |
print 'Loading bottle ...' | |
res = urllib2.urlopen('http://bottlepy.org/bottle.py') | |
code = res.read() | |
with open('bottle.py.cache', 'w') as f: | |
f.write(code) | |
import imp | |
bottle = imp.new_module('bottle') | |
bottle.__dict__['__file__'] = 'http://bottlepy.org/bottle.py' | |
exec code in bottle.__dict__ | |
import json | |
@bottle.route('/') | |
def index(): | |
with open('ng_resource.html', 'r') as f: | |
code = f.read() | |
return code | |
@bottle.route('/get/<id>') | |
def get_user(id): | |
return {'name': u'名字%s' % id, 'id': id} | |
@bottle.route('/save', method="POST") | |
def save_user(): | |
user = json.loads(bottle.request.body.read()) | |
return {'name': user['name'], 'id': user['id']} | |
bottle.run(host='localhost', port=8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment