Skip to content
Myr

__init__.py

This file

Path

examples/tutorial/flaskr/__init__.py

51 lines · 1.4 KiB · Python

Last changed by

use ruff linter and formatter (#5331)David Lordbefore adoption9a12f34

History of this file

Take it

The walk stopped after 200 commits: lines older than ef85270 point at it.

Merge branch '2.2.x'David Lordbefore adoptionef85270

lines 1–33why, one step back
1import os
23from flask import Flask456def create_app(test_config=None):7 """Create and configure an instance of the Flask application."""8 app = Flask(__name__, instance_relative_config=True)9 app.config.from_mapping(10 # a default secret that should be overridden by instance config11 SECRET_KEY="dev",12 # store the database in the instance folder13 DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"),14 )1516 if test_config is None:17 # load the instance config, if it exists, when not testing18 app.config.from_pyfile("config.py", silent=True)19 else:20 # load the test config if passed in21 app.config.update(test_config)2223 # ensure the instance folder exists24 try:25 os.makedirs(app.instance_path)26 except OSError:27 pass2829 @app.route("/hello")30 def hello():31 return "Hello, World!"3233 # register the database commands

use ruff linter and formatter (#5331)David Lordbefore adoption9a12f34

line 34why, one step back
34 from . import db

Merge branch '2.2.x'David Lordbefore adoptionef85270

lines 35–38why, one step back
35
36 db.init_app(app)3738 # apply the blueprints to the app

use ruff linter and formatter (#5331)David Lordbefore adoption9a12f34

lines 39–40why, one step back
39 from . import auth
40 from . import blog

Merge branch '2.2.x'David Lordbefore adoptionef85270

lines 41–51why, one step back
41
42 app.register_blueprint(auth.bp)43 app.register_blueprint(blog.bp)4445 # make url_for('index') == url_for('blog.index')46 # in another app, you might define a separate main index here with47 # app.route, while giving the blog blueprint a url_prefix, but for48 # the tutorial the blog will be the main index49 app.add_url_rule("/", endpoint="index")5051 return app