Almost all web frameworks expect you to produce web pages by combining Python code called a view
with an HTML template; you saw this approach in action in
wsgi_app.py. This approach has gained
traction because of its eminent maintainability: building a dictionary of information is best performed in
plain Python code, and the items fetched and arranged by the view can then easily be included by the
template, so long as the template language supports basic actions like iteration and some form of
(A template is a document consisting of rows and tables, with different ranges and sizes, which facilitates the development of web pages, letters or other content).
It is one of the glories of Python that we use views and templates, and one of the
shames of traditional PHP development that developers would freely intermix HTML and extensive PHP
code to produce a single, unified mess.
Views can also become more testable when their only job is to generate a dictionary of data. A good framework will let you write tests that simply check the raw data returned by the function instead of making you peek repeatedly into fully rendered templates to see if the view corralled its data correctly.
There seem to be two major differences of opinion among the designers and users of the various template languages about what constitutes the best way to use templates:
Since many Python frameworks let you plug in your template language of choice, and only a few of them lock you down to one option, you might find that you can pair your favorite approaches.