Skip to content
Myr

__init__.py

This file

Path

examples/tutorial/flaskr/__init__.py

50 lines · 1.4 KiB · Python

Last changed by

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

History of this file

Take it

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

Merge pull request #2870 from jerr0328/docs-update-cli-scriptinfoDavid Lordbefore adoption93e4b71

lines 1–10why, 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 config

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 11why, one step back
11 SECRET_KEY="dev",

Merge pull request #2870 from jerr0328/docs-update-cli-scriptinfoDavid Lordbefore adoption93e4b71

line 12why, one step back
12 # store the database in the instance folder

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 13why, one step back
13 DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"),

Merge pull request #2870 from jerr0328/docs-update-cli-scriptinfoDavid Lordbefore adoption93e4b71

lines 14–17why, one step back
14 )
1516 if test_config is None:17 # load the instance config, if it exists, when not testing

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 18why, one step back
18 app.config.from_pyfile("config.py", silent=True)

Merge pull request #2870 from jerr0328/docs-update-cli-scriptinfoDavid Lordbefore adoption93e4b71

lines 19–28why, one step back
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 pass28

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 29why, one step back
29 @app.route("/hello")

Merge pull request #2870 from jerr0328/docs-update-cli-scriptinfoDavid Lordbefore adoption93e4b71

line 30why, one step back
30 def hello():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 31why, one step back
31 return "Hello, World!"

Merge pull request #2870 from jerr0328/docs-update-cli-scriptinfoDavid Lordbefore adoption93e4b71

lines 32–34why, one step back
32
33 # register the database commands34 from flaskr import db

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 35why, one step back
35

Merge pull request #2870 from jerr0328/docs-update-cli-scriptinfoDavid Lordbefore adoption93e4b71

lines 36–39why, one step back
36 db.init_app(app)
3738 # apply the blueprints to the app39 from flaskr import auth, blog

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 40why, one step back
40

Merge pull request #2870 from jerr0328/docs-update-cli-scriptinfoDavid Lordbefore adoption93e4b71

lines 41–47why, one step back
41 app.register_blueprint(auth.bp)
42 app.register_blueprint(blog.bp)4344 # make url_for('index') == url_for('blog.index')45 # in another app, you might define a separate main index here with46 # app.route, while giving the blog blueprint a url_prefix, but for47 # the tutorial the blog will be the main index

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 48why, one step back
48 app.add_url_rule("/", endpoint="index")

Merge pull request #2870 from jerr0328/docs-update-cli-scriptinfoDavid Lordbefore adoption93e4b71

lines 49–50why, one step back
49
50 return app