Microservice Patterns and Best Practices by Vinicius Feitosa Pacheco

Microservice Patterns and Best Practices by Vinicius Feitosa Pacheco

Author:Vinicius Feitosa Pacheco
Language: eng
Format: epub
Tags: COM051010 - COMPUTERS / Programming Languages / General, COM051240 - COMPUTERS / Software Development and Engineering / Systems Analysis and Design, COM060180 - COMPUTERS / Web / Web Services and APIs
Publisher: Packt
Published: 2018-01-30T07:21:36+00:00


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



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.