Skip to content

Instantly share code, notes, and snippets.

@desaiashu desaiashu/
Last active Feb 21, 2017

What would you like to do?
Sample Heroku Flask app with MongoHQ
import os
from urlparse import urlparse
from flask import Flask
from pymongo import MongoClient
MONGO_URL = os.environ.get('MONGOHQ_URL')
# Get client
client = MongoClient(MONGO_URL)
# Get database
db = client[urlparse(MONGO_URL).path[1:]]
# Not on an app with the MongoHQ add-on, do some localhost action
client = MongoClient('localhost', 27017)
db = client['MyDB']
app = Flask(__name__)
app.debug = True
def hello():
myObj ={'event':'page_views'})
if not myObj:
myObj = {'event':'page_views', 'count':1}
myObj['count'] += 1
return 'Hello World! ' + str(myObj['count'])
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))'', port=port)

This comment has been minimized.

Copy link

xru commented Feb 17, 2014

works, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.