Created
March 15, 2018 19:00
-
-
Save Ilgrim/941cc8e8a7c6be15c13b65c9acda13d4 to your computer and use it in GitHub Desktop.
Execute at flask initialization
This file contains hidden or 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
| """ | |
| one way to excute something after app.run: | |
| build another app! | |
| From | |
| http://librelist.com/browser/flask/2012/6/7/execute-at-flask-initialization/#a0b5c59832f372f69be6f6e2af4ae4f9 | |
| """ | |
| from flask import Flask | |
| import webbrowser | |
| def create_app(): | |
| app = Flask(__name__) | |
| def run_on_start(*args, **argv): | |
| url = "http://127.0.0.1:5000" | |
| webbrowser.open(url,new=2) | |
| print "opening the webbrowser" | |
| run_on_start() | |
| return app | |
| app = create_app() | |
| @app.route("/") | |
| def hello(): | |
| return "Hello World!" | |
| if __name__ == "__main__": | |
| app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment