The app.py file has the responsibility to run any application. For this file, let's start declaring the imports necessary. Note that, in addition to Flask, we import the Blueprint with all our routes and the MongoEngine instance containing the declaration of our entity:
import os from flask import Flask from views import famous_newsfrom models import db
Now, we go on to instantiate Flask and pass the settings of the environments, the database instance, and the instance of the view routes, as follows:
# instantiate the app app = Flask(__name__) # set config app_settings = os.getenv('APP_SETTINGS') app.config.from_object(app_settings) db.init_app(app) # register blueprints app.register_blueprint(famous_news)
At the end of the file, we have a simple statement to perform Flask on port 5000:
if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)
The file app.py consists of the following formatting:
import os from flask import Flask from views import famous_news from models import db # instantiate the app app = Flask(__name__) # set config app_settings = os.getenv('APP_SETTINGS') app.config.from_object(app_settings) db.init_app(app) # register blueprints app.register_blueprint(famous_news) if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)