Skip to content

Commit

Permalink
♿ Fix logging when ran through flask run
Browse files Browse the repository at this point in the history
This assures applications ran via ``flask run`` will grab app, but
tests or anything importing will not implicitly create app (and hook
into pymongo monitoring).

Without this, flask would implicitly use create_app to start Flask,
which won't properly bind pymongo.
  • Loading branch information
tony committed Oct 28, 2018
1 parent d9536d3 commit 0837fc5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/flask_todo/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os

from flask import Flask
from flask_mongoengine import MongoEngine

Expand Down Expand Up @@ -74,4 +76,9 @@ def index():
return app


app = create_app()
if __name__ == '__main__' or os.getenv('FLASK_RUN_FROM_CLI') == 'true':
"""
For some reason falling back onto create_app when running ``flask run`` doesn't
bind pymongo.monitoring. See also: http://flask.pocoo.org/docs/1.0/cli/.
"""
app = create_app()

0 comments on commit 0837fc5

Please sign in to comment.