https://jinja.palletsprojects.com/en/master/api/#jinja2.Environment
class jinja2.Environment([options])
初始化参数
参数 | 描述 |
---|---|
block_start_string | The string marking the beginning of a block. Defaults to '{%'. |
block_end_string | The string marking the end of a block. Defaults to '%}'. |
variable_start_string | The string marking the beginning of a print statement. Defaults to '{{'. |
variable_end_string | The string marking the end of a print statement. Defaults to '}}'. |
comment_start_string | The string marking the beginning of a comment. Defaults to '{#'. |
comment_end_string | The string marking the end of a comment. Defaults to '#}'. |
line_statement_prefix | 自定义语句开头,替代block_start_string |
line_comment_prefix | 自定义语句结尾,替代block_start_string |
trim_blocks | |
lstrip_blocks | |
newline_sequence | |
keep_trailing_newline | |
extensions | |
optimized | |
undefined | |
finalize | |
autoescape | |
loader | |
cache_size | |
auto_reload | |
bytecode_cache | |
enable_async |
对象方法
方法 | 描述 |
---|---|
shared | |
sandboxed | |
filters | |
tests | |
globals | |
policies | |
code_generator_class | |
context_class | |
overlay([options]) | |
undefined([hint, obj, name, exc]) | |
add_extension(extension) | |
compile_expression(source, undefined_to_none=True) | |
compile_templates(target, extensions=None, filter_func=None, zip=‘deflated’, log_function=None, ignore_errors=True) | |
extend(**attributes) | |
from_string(source, globals=None, template_class=None) | |
get_or_select_template(template_name_or_list, parent=None, globals=None) | |
get_template(name, parent=None, globals=None) | |
join_path(template, parent) | |
list_templates(extensions=None, filter_func=None) | |
select_template(names, parent=None, globals=None) |