Home / Function/ create_app() — flask Function Reference

create_app() — flask Function Reference

Architecture documentation for the create_app() function in __init__.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  552a82b4_7c75_bff0_0de1_77689e291c3b["create_app()"]
  6e447255_b990_e599_2820_9fe2d66cda05["__init__.py"]
  552a82b4_7c75_bff0_0de1_77689e291c3b -->|defined in| 6e447255_b990_e599_2820_9fe2d66cda05
  style 552a82b4_7c75_bff0_0de1_77689e291c3b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

examples/tutorial/flaskr/__init__.py lines 6–48

def create_app(test_config=None):
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        # a default secret that should be overridden by instance config
        SECRET_KEY="dev",
        # store the database in the instance folder
        DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile("config.py", silent=True)
    else:
        # load the test config if passed in
        app.config.update(test_config)

    # ensure the instance folder exists
    os.makedirs(app.instance_path, exist_ok=True)

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

    # register the database commands
    from . import db

    db.init_app(app)

    # apply the blueprints to the app
    from . import auth
    from . import blog

    app.register_blueprint(auth.bp)
    app.register_blueprint(blog.bp)

    # make url_for('index') == url_for('blog.index')
    # in another app, you might define a separate main index here with
    # app.route, while giving the blog blueprint a url_prefix, but for
    # the tutorial the blog will be the main index
    app.add_url_rule("/", endpoint="index")

    return app

Subdomains

Frequently Asked Questions

What does create_app() do?
create_app() is a function in the flask codebase, defined in examples/tutorial/flaskr/__init__.py.
Where is create_app() defined?
create_app() is defined in examples/tutorial/flaskr/__init__.py at line 6.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free