__init__.py
This file
Path
examples/tutorial/flaskr/__init__.py
48 lines · 1.4 KiB · Python
Last changed by
Merge remote-tracking branch 'origin/stable'David Lordbefore adoptiond3b78fd
History of this fileTake it
1import os23from 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 os.makedirs(app.instance_path, exist_ok=True)2526 @app.route("/hello")27 def hello():28 return "Hello, World!"2930 # register the database commands31 from . import db3233 db.init_app(app)3435 # apply the blueprints to the app36 from . import auth37 from . import blog3839 app.register_blueprint(auth.bp)40 app.register_blueprint(blog.bp)4142 # make url_for('index') == url_for('blog.index')43 # in another app, you might define a separate main index here with44 # app.route, while giving the blog blueprint a url_prefix, but for45 # the tutorial the blog will be the main index46 app.add_url_rule("/", endpoint="index")4748 return app