Skip to Content
Python Microservices Development
book

Python Microservices Development

by Tarek Ziadé
July 2017
Beginner to intermediate
340 pages
7h 43m
English
Packt Publishing
Content preview from Python Microservices Development

View and Template

When a request is received, and a view is invoked, Flask-SQLAlchemy will set up a database session object inside an application context. The following is a fully functional Flask app that uses the schema described earlier in a View that can be queried from /users:

    from flask import Flask, render_template      app = Flask(__name__)      @app.route('/users')     def users():         users = db.session.query(User)         return render_template("users.html", users=users)      if __name__ == '__main__':         db.init_app(app)         db.create_all(app=app)         app.run() 

When the db.session.query() method is called, it performs a query on the database and turns every result from the User table into User objects that are passed to the users.html Jinja template for ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Microservices Development - Second Edition

Python Microservices Development - Second Edition

Simon Fraser, Tarek Ziadé
Python Web Development with Sanic

Python Web Development with Sanic

Stephen Sadowski, Adam Hopkins

Publisher Resources

ISBN: 9781785881114Supplemental Content