Create a new app.py
file within the api
folder. The following lines show the code that creates a Flask application. The code file for the sample is included in the restful_python_chapter_06_01
folder.
from flask import Flask def create_app(config_filename): app = Flask(__name__) app.config.from_object(config_filename) from models import db db.init_app(app) from views import api_bp app.register_blueprint(api_bp, url_prefix='/api') return app
The code in the api/app.py
file declares a create_app
function that receives the configuration file name in the config_filename
argument, set ups a Flask app with this configuration file, and returns the app
object. First, the function creates the main entry point for the Flask application named app
. Then, the code calls the app.config.from_object
method with the config_filename
received as an argument. This way, the Flask app uses the values that are specified...