Last active
August 29, 2015 14:04
-
-
Save lgarvey/9f127297e742d0bada48 to your computer and use it in GitHub Desktop.
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
# | |
# Connecting to MonogHQ via heroku with flask and mongoengine | |
# | |
# heroku/mongohq exposes the mongodb connection uri in the os.envion['MONGOHQ_URL'] | |
# | |
# config.py | |
import os | |
MONGO_URI = os.environ.get('MONGOHQ_URL', None) | |
# ... | |
MONGODB_SETTINGS = {} | |
# MongoDB Config | |
if not MONGO_URI: | |
# local config: | |
MONGODB_SETTINGS['db'] = 'localdev' | |
MONGODB_SETTINGS['host'] = 'localhost' | |
MONGODB_SETTINGS['port'] = 27017 | |
else: | |
# heroku: | |
# mongoengine.connect() accepts a host uri parameter, but also requires | |
# a db parameter. So grab it from the end of the host uri. | |
MONGODB_SETTINGS['db'] = MONGO_URI.split("/")[-1] | |
MONGODB_SETTINGS['host'] = MONGO_URI | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment