Skip to main content

fresco的模板系统集成

项目描述

Jinja2 的示例用法:

from fresco import FrescoApp
from fresco_template import Jinja2
from jinja2 import PackageLoader

app = FrescoApp()
jinja2 = Jinja2(loader=PackageLoader('mypackage', 'template/dir'))
jinja2.init_app(app)


@jinja2.contextprocessor
def default_context():
    # Return a dictionary of variables always to be included in the
    # template context.
    #
    # NB the fresco context object and urlfor function are already included
    # in the template context by default.
    return {}

@jinja2.render('page.html')
def myview():
    return {'var': 'value'}

与变色龙相同的例子:

from fresco import FrescoApp
from fresco_template import Chameleon
from chameleon import PageTemplateLoader

app = FrescoApp()

loader = PageTemplateLoader(['template/dir'], auto_reload=True)
chameleon = Chameleon(loader)
chameleon.init_app(app)


@chameleon.contextprocessor
def default_context():
    # Return a dictionary of variables always to be included in the
    # template context.
    #
    # NB the fresco context object and urlfor function are already included
    # in the template context by default.
    return {}

@chameleon.render('page.html')
def myview():
    return {'var': 'value'}

1.0.0(2020-09-27 发布)

  • 放弃了 Python 2 兼容性

  • 修复了调用as_string作为函数装饰器时的异常。

  • 修复了弃用警告

0.3.1(2016-11-29发布)

0.3.0(2015-09-25发布)

  • 添加了对 Kajiki 的支持

  • 环境变量的名称已更改为loader,不再直接在 TemplateEnvironment 对象上可用,而是通过插件属性。例如:

    from jinja2 import Environment, FileSystemLoader
    from fresco_template import Jinja2
    
    # Old style - BROKEN in 0.3 release:
    j2 = Jinja2(environment=Environment(FileSystemLoader('templates')))
    j2.environment.install_gettext_translations(my_translation_module)
    
    # New style:
    j2 = Jinja2(Environment(autoescape=True, FileSystemLoader('templates')))
    j2.plugin.loader.install_gettext_translations(my_translation_module)
  • 任何自定义插件都需要重写。有关示例,请参阅任何默认插件。

0.2.1

  • TemplateContent类现在在实例化时调用所有上下文处理器。这确保了在发送响应头之前总是调用上下文处理器。

0.2

初始发行

0.1

(未发布版本)

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

fresco-template-1.0.0.tar.gz (9.6 kB 查看哈希)

已上传 source

内置分布

fresco_template-1.0.0-py3-none-any.whl (10.7 kB 查看哈希

已上传 py3