- Flask By Example
- Gareth Dwyer
- 236字
- 2021-07-09 20:06:54
Introducing Jinja
Jinja is a Python template engine. It allows us to easily define dynamic blocks of HTML which are populated by Python. HTML templates are useful even for static websites which have multiple pages. Usually, there are some common elements, such as headers and footers, on every page. Although it is possible to maintain each page inpidually for static websites, this requires that a single change be made in multiple places if the change is made to a shared section. Flask was built on top of Jinja, so although it is possible to use Jinja without Flask, Jinja is still an inherent part of Flask, and Flask provides several methods to work directly with Jinja. Generally, Flask assumes nothing about the structure of your application except what you tell it, and prefers providing functionality through optional plugins. Jinja is somewhat of an exception to this. Flask gives you Jinja by default, and assumes that you store all your Jinja templates in a subdirectory of your application named templates
.
Once we've created templates, we'll make calls from our Flask app to render these templates. Rendering involves parsing the Jinja code, inserting any dynamic data, and creating pure HTML to be returned to a user's browser. All of this is done behind the scenes though, so it can get a bit confusing as to what is being done where. We'll take things one step at a time.
- Practical Data Analysis Cookbook
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- JavaScript+jQuery網頁特效設計任務驅動教程(第2版)
- Learning Bayesian Models with R
- Python 3網絡爬蟲實戰
- 你不知道的JavaScript(中卷)
- INSTANT Django 1.5 Application Development Starter
- SQL Server 2016數據庫應用與開發
- Integrating Facebook iOS SDK with Your Application
- iOS自動化測試實戰:基于Appium、Python與Pytest
- C專家編程
- Learning Material Design
- SciPy Recipes
- JavaScript程序設計:基礎·PHP·XML
- 愛上C語言:C KISS