低層 API 暴露的功能對理解一些實現細節、調試目的或高級?[*擴展*](http://docs.jinkan.org/docs/jinja2/extensions.html#jinja-extensions)?技巧是有用的。除非你準確地了解你在做什么,否則 不推薦使用這些 API 。
Environment.lex(*source*,?*name=None*,?*filename=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Environment.lex "Permalink to this definition")
Lex the given sourcecode and return a generator that yields tokens as tuples in the form?(lineno,?token_type,?value). This can be useful for?[*extension development*](http://docs.jinkan.org/docs/jinja2/extensions.html#writing-extensions)?and debugging templates.
This does not perform preprocessing. If you want the preprocessing of the extensions to be applied you have to filter source through the?[preprocess()](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Environment.preprocess "jinja2.Environment.preprocess")?method.
Environment.parse(*source*,?*name=None*,?*filename=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Environment.parse "Permalink to this definition")
Parse the sourcecode and return the abstract syntax tree. This tree of nodes is used by the compiler to convert the template into executable source- or bytecode. This is useful for debugging or to extract information from templates.
If you are?[*developing Jinja2 extensions*](http://docs.jinkan.org/docs/jinja2/extensions.html#writing-extensions)?this gives you a good overview of the node tree generated.
Environment.preprocess(*source*,?*name=None*,?*filename=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Environment.preprocess "Permalink to this definition")
Preprocesses the source with all extensions. This is automatically called for all parsing and compiling methods but?*not*?for?[lex()](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Environment.lex "jinja2.Environment.lex")?because there you usually only want the actual source tokenized.
Template.new_context(*vars=None*,?*shared=False*,?*locals=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Template.new_context "Permalink to this definition")
Create a new?Context?for this template. The vars provided will be passed to the template. Per default the globals are added to the context. If shared is set to?True?the data is passed as it to the context without adding the globals.
locals?can be a dict of local variables for internal usage.
Template.root_render_func(*context*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Template.root_render_func "Permalink to this definition")
這是低層的渲染函數。它接受一個必須由相同模板或兼容的模板的?[new_context()](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Template.new_context "jinja2.Template.new_context")?創建的?Context?。這個渲染函數由編譯器從 模板代碼產生,并返回一個生產 unicode 字符串的生成器。
如果模板代碼中發生了異常,模板引擎不會重寫異常而是直接傳遞原始的異常。 事實上,這個函數只在?[render()](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Template.render "jinja2.Template.render")?/?[generate()](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Template.generate "jinja2.Template.generate")?/?[stream()](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Template.stream "jinja2.Template.stream")?的調用里被調用。
Template.blocks[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Template.blocks "Permalink to this definition")
一個塊渲染函數的字典。其中的每個函數與?[root_render_func()](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Template.root_render_func "jinja2.Template.root_render_func")?的工作 相同,并且有相同的限制。
Template.is_up_to_date[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Template.is_up_to_date "Permalink to this definition")
如果有可用的新版本模板,這個屬性是?False?,否則是?True?。
注意
低層 API 是易碎的。未來的 Jinja2 的版本將不會試圖以不向后兼容的方式修改它, 而是在 Jinja2 核心的修改中表現出來。比如如果 Jinja2 在之后的版本中引入一 個新的 AST 節點,它會由?[parse()](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Environment.parse "jinja2.Environment.parse")?返回。
- 介紹
- 預備知識
- 安裝
- 基本 API 使用
- 實驗性的 Python 3 支持
- API
- 基礎
- Unicode
- 高層 API
- 自動轉義
- 標識符的說明
- 未定義類型
- 上下文
- 加載器
- 字節碼緩存
- 實用工具
- 異常
- 自定義過濾器
- 求值上下文
- 自定義測試
- 全局命名空間
- 低層 API
- 元 API
- 沙箱
- API
- 運算符攔截
- 模板設計者文檔
- 概要
- 變量
- 過濾器
- 測試
- 注釋
- 空白控制
- 轉義
- 行語句
- 模板繼承
- HTML 轉義
- 控制結構清單
- 導入上下文行為
- 表達式
- 內置過濾器清單
- 內置測試清單
- 全局函數清單
- 擴展
- 自動轉義擴展
- 擴展
- 添加擴展
- i18n 擴展
- 表達式語句
- 循環控制
- With 語句
- 自動轉義擴展
- 編寫擴展
- 集成
- Babel 集成
- Pylons
- TextMate
- Vim
- 從其它的模板引擎切換
- Jinja1
- Django
- Mako
- 提示和技巧
- Null-Master 退回
- 交替的行
- 高亮活動菜單項
- 訪問父級循環