官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 曲靖市| 德格县| 民权县| 长泰县| 宁阳县| 灌阳县| 宜昌市| 磐安县| 台安县| 明星| 阿拉尔市| 河北省| 綦江县| 神农架林区| 九台市| 龙胜| 望江县| 迭部县| 云霄县| 安图县| 阜平县| 石城县| 定西市| 锦州市| 敦化市| 江川县| 漠河县| 潞城市| 汉川市| 边坝县| 元江| 尤溪县| 思茅市| 皮山县| 通山县| 孝昌县| 长宁区| 丰宁| 灵台县| 江孜县| 庆元县|