Book Image

Python for Google App Engine

By : Massimiliano Pippi
Book Image

Python for Google App Engine

By: Massimiliano Pippi

Overview of this book

Table of Contents (15 chapters)
Python for Google App Engine
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

HTML templates with Jinja2


Web applications provide rich and complex HTML user interfaces, and Notes is no exception but, so far, response objects in our applications contained just small pieces of text. We could include HTML tags as strings in our Python modules and write them in the response body but we can imagine how easily it could become messy and hard to maintain the code. We need to completely separate the Python code from HTML pages and that's exactly what a template engine does. A template is a piece of HTML code living in its own file and possibly containing additional, special tags; with the help of a template engine, from the Python script, we can load this file, properly parse special tags, if any, and return valid HTML code in the response body. App Engine includes in the Python runtime a well-known template engine: the Jinja2 library.

To make the Jinja2 library available to our application, we need to add this code to the app.yaml file under the libraries section:

libraries...