- 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.
- Mastering RabbitMQ
- INSTANT OpenCV Starter
- C語言程序設計基礎與實驗指導
- Network Automation Cookbook
- OpenStack Cloud Computing Cookbook(Fourth Edition)
- PHP網絡編程學習筆記
- Learning Neo4j 3.x(Second Edition)
- 深入淺出RxJS
- Hands-On Enterprise Automation with Python.
- 單片機C語言程序設計實訓100例
- 第一行代碼 C語言(視頻講解版)
- Python語言實用教程
- Java零基礎實戰
- 細說Python編程:從入門到科學計算
- Android Studio開發實戰:從零基礎到App上線 (移動開發叢書)