peter58228
3/25/2020 - 7:15 AM

Flask apps minimal blueprint

Flask apps minimal blueprint

Folder structure.

/project
├── /MyApp
│   ├── __init__.py
│   └── routes.py
└── wsgi.py

Run flask run inside your project folder to start your server.

from MyApp import create_app # <-- MyApp = MyApp Folder

app = create_app()

if __name__ == "__main__":
    app.run(host='127.0.0.1', debug=True)
"""Initialize Flask Application."""
from flask import Flask

def create_app():
    """Construct the core application."""
    app = Flask(__name__)

    with app.app_context():
        from . import routes
        return app
"""Route declaration."""
from flask import current_app as app

@app.route("/")
def home():
    return "Hello World!"