Skip to content

Instantly share code, notes, and snippets.

@ewangke
Created July 28, 2012 10:12
Show Gist options
  • Save ewangke/3192772 to your computer and use it in GitHub Desktop.
Save ewangke/3192772 to your computer and use it in GitHub Desktop.
bottle with pymongo and mongoengine on AppFog
bottle
pymongo
mongoengine
from bottle import run, get, request, app
from mongoengine import *
import json
import os
# application object required by wsgi, appfog use gunicorn with wsgi
application = app()
@get('/')
@get('/test')
def test():
services = json.loads(os.environ.get("VCAP_SERVICES", "{}"))
creds = services['mongodb-1.8'][0]['credentials']
conn = connect(creds['db'], username=creds['username'], password=creds['password'], host=creds['hostname'], port=creds['port'])
# do whatever after establish the mongodb connection
conn.disconnect()
return creds
if __name__ == '__main__':
run(host='0.0.0.0', port=80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment