当前位置: 首页>>代码示例>>Python>>正文


Python jinja.Environment类代码示例

本文整理汇总了Python中jinja.Environment的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: model_run

 def model_run(self, model_context):
     context = self._build_context(model_context)
     # mostrar el reporte
     fileloader = PackageLoader('m2000', 'templates')
     env = Environment(loader=fileloader)
     t = env.get_template('indicadores.html')
     yield PrintHtmlLandscape(t.render(context))
开发者ID:frandibar,项目名称:m2000,代码行数:7,代码来源:reports.py

示例2: configure

def configure(convert_filters=DEFAULT_FILTERS, loader=None, **options):
    """
    Initialize the system.
    """
    global env

    if env:
        warnings.warn("Jinja already initialized.")
        return

    # setup environment
    if loader is None:
        loaders = tuple(FileSystemLoader(l) for l in settings.TEMPLATE_DIRS)
        if not loaders:
            loader = None
        elif len(loaders) == 1:
            loader = loaders[0]
        else:
            loader = ChoiceLoader(loaders)
    env = Environment(loader=loader, **options)

    # convert requested filters
    for name in convert_filters:
        env.filters[name] = convert_django_filter(name)

    # Register URL template tag
    env.globals[url] = url

    # import templatetags of installed apps
    for app in settings.INSTALLED_APPS:
        try:
            __import__(app + '.templatetags')
        except ImportError:
            pass
开发者ID:dcramer,项目名称:jinja1-djangosupport,代码行数:34,代码来源:_djangosupport.py

示例3: babel_extract

def babel_extract(fileobj, keywords, comment_tags, options):
    """
    Simple extractor to get some basic Babel support.
    """
    env = Environment()
    for lineno, sg, pl in env.get_translations_for_string(fileobj.read()):
        yield lineno, None, (sg, pl), ''
开发者ID:BackupGGCode,项目名称:sphinx,代码行数:7,代码来源:_jinja.py

示例4: load_template

def load_template(config, templateName):
    """"Charge un template"""
    if config.template_dir == "":
        environment = Environment(loader=PackageLoader('tracforge', 'templates'))
    else:
        environment = Environment(loader=FileSystemLoader(config.template_dir))
    return environment.get_template(templateName)
开发者ID:francois2metz,项目名称:trac-forge,代码行数:7,代码来源:projects.py

示例5: model_run

 def model_run(self, model_context):
     context = self._build_context(model_context)
     # mostrar el reporte
     fileloader = PackageLoader("canasta", "templates")
     env = Environment(loader=fileloader)
     t = env.get_template("precios.html")
     yield PrintHtml(t.render(context))
开发者ID:frandibar,项目名称:Canasta-Familiar,代码行数:7,代码来源:reports.py

示例6: render

        def render(printer):
            client_address = "<br/>".join(["2 Azalea St.", "Fredericksburg", "22406 VA"])

            import datetime

            ts = datetime.datetime.today()
            datestring = "Date: %s/%s/%s" % (ts.month, ts.day, ts.year)

            view_content = view.toHtml()
            context = {
                "logo": icon,
                "company_name": "Conceptive Engineering",
                "company_address_1": "L. Van Bauwelstraat 16",
                "company_address_2": "2220 Heist-op-den-Berg",
                "city": "Belgium",
                "date": datestring,
                "client_address": client_address,
                "client_name": "Client",
                "content": view_content,
                "signature": "M. Anager",
            }

            from jinja import Environment, FileSystemLoader

            fileloader = FileSystemLoader(settings.CAMELOT_TEMPLATES_DIRECTORY)
            e = Environment(loader=fileloader)
            t = e.get_template("base.html")
            html = t.render(context)

            doc = QtGui.QTextDocument()
            doc.setHtml(html)
            doc.print_(self.printer)
开发者ID:anilet,项目名称:time-manage,代码行数:32,代码来源:printer.py

示例7: test_no_variable_block

def test_no_variable_block():
    env = Environment('{%', '%}', None, None)
    tmpl = env.from_string(NO_VARIABLE_BLOCK)
    assert tmpl.render(foo=42, seq=range(2)).splitlines() == [
        '42',
        '01',
        'foo is 42',
        '42 foos'
    ]
开发者ID:dcramer,项目名称:jinja1-djangosupport,代码行数:9,代码来源:test_parser.py

示例8: test_dict_loader

def test_dict_loader():
    env = Environment(loader=dict_loader)
    tmpl = env.get_template('justdict.html')
    assert tmpl.render().strip() == 'FOO'
    try:
        env.get_template('missing.html')
    except TemplateNotFound:
        pass
    else:
        raise AssertionError('expected template exception')
开发者ID:dcramer,项目名称:jinja1-djangosupport,代码行数:10,代码来源:test_loaders.py

示例9: test_super

def test_super():
    env = Environment(loader=DictLoader({
        'a': '{% block intro %}INTRO{% endblock %}|'
             'BEFORE|{% block data %}INNER{% endblock %}|AFTER',
        'b': '{% extends "a" %}{% block data %}({{ '
             'super() }}){% endblock %}',
        'c': '{% extends "b" %}{% block intro %}--{{ '
             'super() }}--{% endblock %}\n{% block data '
             '%}[{{ super() }}]{% endblock %}'
    }))
    tmpl = env.get_template('c')
    assert tmpl.render() == '--INTRO--|BEFORE|[(INNER)]|AFTER'
开发者ID:dcramer,项目名称:jinja1-djangosupport,代码行数:12,代码来源:test_inheritance.py

示例10: test_memcached_loader

def test_memcached_loader():
    env = Environment(loader=memcached_loader)
    tmpl = env.get_template('test.html')
    assert tmpl.render().strip() == 'BAR'
    tmpl = env.get_template('foo/test.html')
    assert tmpl.render().strip() == 'FOO'
    try:
        env.get_template('missing.html')
    except TemplateNotFound:
        pass
    else:
        raise AssertionError('expected template exception')
开发者ID:dcramer,项目名称:jinja1-djangosupport,代码行数:12,代码来源:test_loaders.py

示例11: init

 def init(self, builder):
     self.templates = {}
     base_templates_path = path.join(path.dirname(__file__), 'templates')
     ext_templates_path = [path.join(builder.confdir, dir)
                           for dir in builder.config.templates_path]
     self.templates_path = [base_templates_path] + ext_templates_path
     loader = SphinxFileSystemLoader(base_templates_path, ext_templates_path)
     if builder.translator is not None:
         self.jinja_env = TranslatorEnvironment(loader=loader,
                 friendly_traceback=False, translator=builder.translator)
     else:
         self.jinja_env = Environment(loader=loader,
                 # disable traceback, more likely that something
                 # in the application is broken than in the templates
                 friendly_traceback=False)
开发者ID:BackupGGCode,项目名称:sphinx,代码行数:15,代码来源:_jinja.py

示例12: test_package_loader

def test_package_loader():
    env = Environment(loader=package_loader)
    for x in xrange(2):
        tmpl = env.get_template('test.html')
        assert tmpl.render().strip() == 'BAR'
        try:
            env.get_template('missing.html')
        except TemplateNotFound:
            pass
        else:
            raise AssertionError('expected template exception')

        # second run in native mode (no pkg_resources)
        package_loader.force_native = True
        del package_loader._load_func
开发者ID:dcramer,项目名称:jinja1-djangosupport,代码行数:15,代码来源:test_loaders.py

示例13: render

def render(filename, data={}):
    import cherrypy
    from jinja import Environment, FileSystemLoader

    environment = Environment(loader=FileSystemLoader("views"))

    data["VERSION"] = encode_unicode(file("VERSION").read()).strip()
    try:
        data["flash"] = get_flash()
        data["flash_class"] = cherrypy.session["flash_class"]
    except KeyError:
        pass
    data.update(helpers)
    data["User"] = cherrypy.session.get("User")
    return environment.get_template(filename + ".jinja").render(data)
开发者ID:adeel,项目名称:razgovore,代码行数:15,代码来源:util.py

示例14: BuiltinTemplates

class BuiltinTemplates(TemplateBridge):
    def init(self, builder):
        self.templates = {}
        base_templates_path = path.join(path.dirname(__file__), 'templates')
        ext_templates_path = [path.join(builder.confdir, dir)
                              for dir in builder.config.templates_path]
        self.templates_path = [base_templates_path] + ext_templates_path
        loader = SphinxFileSystemLoader(base_templates_path, ext_templates_path)
        if builder.translator is not None:
            self.jinja_env = TranslatorEnvironment(loader=loader,
                    friendly_traceback=False, translator=builder.translator)
        else:
            self.jinja_env = Environment(loader=loader,
                    # disable traceback, more likely that something
                    # in the application is broken than in the templates
                    friendly_traceback=False)

    def newest_template_mtime(self):
        return max(mtimes_of_files(self.templates_path, '.html'))

    def render(self, template, context):
        if template in self.templates:
            return self.templates[template].render(context)
        templateobj = self.templates[template] = \
                      self.jinja_env.get_template(template)
        return templateobj.render(context)
开发者ID:BackupGGCode,项目名称:sphinx,代码行数:26,代码来源:_jinja.py

示例15: model_run

    def model_run(self, model_context):
        from camelot.view.action_steps import PrintHtml
        import datetime
        import os
        from jinja import Environment, FileSystemLoader
        from pkg_resources import resource_filename

        fileloader = FileSystemLoader(resource_filename(rms.__name__, 'templates'))
        e = Environment(loader=fileloader)
        resursa = model_context.get_object()
        context = {
            'header': resursa.nume,
            'title': 'Raport resurse umane',
            'style': '.label { font-weight:bold; }',
            'persoana': resursa,
            'footer': str(datetime.datetime.now().year)
        }
        t = e.get_template('resurse_umane.html')
        yield PrintHtml(t.render(context))
开发者ID:rolisz,项目名称:proiect_colectiv,代码行数:19,代码来源:Rapoarte.py


注:本文中的jinja.Environment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。