Skip to content

Instantly share code, notes, and snippets.

@yszou
Created July 2, 2013 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yszou/5911800 to your computer and use it in GitHub Desktop.
Save yszou/5911800 to your computer and use it in GitHub Desktop.
# -*- 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