from flask import *
from flask_mongoengine import MongoEngine, Document
from bson import json_util

# Create Flask app.
app = Flask(__name__)

# Configure the database.
app.config['MONGODB_SETTINGS'] = {'DB': 'test'}
db = MongoEngine(app)

# Define a Post object for the database.
class Post(Document):
	author = db.StringField(required=True)
	body = db.StringField(required=True, min_length=0)
	title = db.StringField(required=True, min_length=0)

# Define a root route. (Say that 10x quick..)
@app.route('/')
def base():
	return "/posts, GET POST, Gets or creates Post records."

# Define a 'posts' route which can create posts and return a list of all posts (in JSON).
@app.route('/posts', methods=['GET', 'POST'])
def posts():
	if request.method == 'POST':
		post = createPost(request.form['title'], request.form['body'], request.form['author'])
		return jsonify(post)
	else:
		objects = Post.objects
		return jsonify(objects)

# Helper method to create posts.
def createPost(title, body, author):
	post = Post(title=title, body=body, author=author)
	post.save()
	return post
@@ -91,16 +91,154 @@
 son_util
+%0Aimport os %0A%0Aif 'MONGODB_URI' in os.environ.keys():%0A%09mongo_uri = os.environ%5B'MONGODB_URI'%5D%0Aelse:%0A%09mongo_uri = 'localhost'%0Aprint(mongo_uri)
 %0A%0A# Crea
@@ -338,11 +338,13 @@
  = %7B
-'DB
+%0A%09'db
 ': '
@@ -348,16 +348,37 @@
 : 'test'
+,%0A%09'host': mongo_uri%0A
 %7D%0Adb = M

Add environment database configuration