def before_request(): """Setup some common daos so we can use them across the board""" flask.g.connect = mongoengine.connect('blogizzle') flask.g.now = datetime.datetime.now() flask.g.post_count = len(Post.objects())
def read(slug): post = Post.objects(slug = slug)[0] return flask.render_template('post.html', post = post)
from blogizzle.Post import Post from mongoengine import connect connect('blogizzle', host='Hippo.local') post = Post(title="Hello World!", body="Blah blah blah", ip="127.0.0.1") try: post.save() except: post._id = Post.objects(slug=post.slug).first()._id post.save()