Preparing the app to run

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 ...

Get Microservice Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.