Created
July 28, 2012 10:12
-
-
Save ewangke/3192772 to your computer and use it in GitHub Desktop.
bottle with pymongo and mongoengine on AppFog
This file contains 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
bottle | |
pymongo | |
mongoengine |
This file contains 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
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