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


Python template.Engine方法代码示例

本文整理汇总了Python中django.template.Engine方法的典型用法代码示例。如果您正苦于以下问题:Python template.Engine方法的具体用法?Python template.Engine怎么用?Python template.Engine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template的用法示例。


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

示例1: page_not_found

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def page_not_found(request, template_name='404.html'):
    """
    Default 404 handler.

    Templates: :template:`404.html`
    Context:
        request_path
            The path of the requested URL (e.g., '/app/pages/bad_page/')
    """
    context = {'request_path': request.path}
    try:
        template = loader.get_template(template_name)
        body = template.render(context, request)
        content_type = None             # Django will use DEFAULT_CONTENT_TYPE
    except TemplateDoesNotExist:
        template = Engine().from_string(
            '<h1>Not Found</h1>'
            '<p>The requested URL {{ request_path }} was not found on this server.</p>')
        body = template.render(Context(context))
        content_type = 'text/html'
    return http.HttpResponseNotFound(body, content_type=content_type) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:23,代码来源:defaults.py

示例2: directory_index

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def directory_index(path, fullpath):
    try:
        t = loader.select_template([
            'static/directory_index.html',
            'static/directory_index',
        ])
    except TemplateDoesNotExist:
        t = Engine().from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
    files = []
    for f in os.listdir(fullpath):
        if not f.startswith('.'):
            if os.path.isdir(os.path.join(fullpath, f)):
                f += '/'
            files.append(f)
    c = Context({
        'directory': path + '/',
        'file_list': files,
    })
    return HttpResponse(t.render(c)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:21,代码来源:static.py

示例3: directory_index

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def directory_index(path, fullpath):
    try:
        t = loader.select_template([
            'static/directory_index.html',
            'static/directory_index',
        ])
    except TemplateDoesNotExist:
        t = Engine(libraries={'i18n': 'django.templatetags.i18n'}).from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
        c = Context()
    else:
        c = {}
    files = []
    for f in os.listdir(fullpath):
        if not f.startswith('.'):
            if os.path.isdir(os.path.join(fullpath, f)):
                f += '/'
            files.append(f)
    c.update({
        'directory': path + '/',
        'file_list': files,
    })
    return HttpResponse(t.render(c)) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:24,代码来源:static.py

示例4: handle

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def handle(self, *args, **options):
        self.type = options['type']
        self.name = options['name']
        management.call_command('startapp', self.name)
        dir_name = ['management', Path('management/commands')]
        self.mk_dir(dir_name)

        if self.type == 'theme':
            dir_name = ['static', Path('static/' + self.name), 'templates', Path('templates/' + self.name)]
            self.mk_dir(dir_name)

        context = Context({
            'app_name': self.name,
            'app_camel_name': self.name[0].upper() + self.name[1:],
            'app_upper_name': self.name.upper(),
            'deeru_type': self.type
        }, autoescape=False)

        for template_name, new_file in self.get_app_templates():
            template = Engine().from_string(self.get_template_str(template_name))
            content = template.render(context)
            new_file.write_text(content) 
开发者ID:gojuukaze,项目名称:DeerU,代码行数:24,代码来源:start.py

示例5: setUpClass

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def setUpClass(cls):
        test_app_root = settings.TENANT_APPS_DIR
        settings.MULTITENANT_TEMPLATE_DIRS = [
            os.path.join(test_app_root, "tenants/%s/templates")
        ]

        cls.engine = Engine(
            loaders=[
                (
                    "django_tenants.template.loaders.cached.Loader",
                    ["django_tenants.template.loaders.filesystem.Loader"],
                )
            ]
        )

        super().setUpClass() 
开发者ID:django-tenants,项目名称:django-tenants,代码行数:18,代码来源:test_filesystem.py

示例6: directory_index

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def directory_index(path, fullpath):
    try:
        t = loader.select_template([
            'static/directory_index.html',
            'static/directory_index',
        ])
    except TemplateDoesNotExist:
        t = Engine(libraries={'i18n': 'django.templatetags.i18n'}).from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
        c = Context()
    else:
        c = {}
    files = []
    for f in fullpath.iterdir():
        if not f.name.startswith('.'):
            url = str(f.relative_to(fullpath))
            if f.is_dir():
                url += '/'
            files.append(url)
    c.update({
        'directory': path + '/',
        'file_list': files,
    })
    return HttpResponse(t.render(c)) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:25,代码来源:static.py

示例7: test_url_reverse_view_name

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def test_url_reverse_view_name(self):
        """
        #19827 -- url tag should keep original strack trace when reraising
        exception.
        """
        t = Engine().from_string('{% url will_not_match %}')
        c = Context()
        try:
            t.render(c)
        except NoReverseMatch:
            tb = sys.exc_info()[2]
            depth = 0
            while tb.tb_next is not None:
                tb = tb.tb_next
                depth += 1
            self.assertGreater(depth, 5, "The traceback context was lost when reraising the traceback.") 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:tests.py

示例8: test_recursive_multiple_loaders

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def test_recursive_multiple_loaders(self):
        engine = Engine(
            dirs=[os.path.join(RECURSIVE, 'fs')],
            loaders=[(
                'django.template.loaders.locmem.Loader', {
                    'one.html': (
                        '{% extends "one.html" %}{% block content %}{{ block.super }} locmem-one{% endblock %}'
                    ),
                    'two.html': (
                        '{% extends "two.html" %}{% block content %}{{ block.super }} locmem-two{% endblock %}'
                    ),
                    'three.html': (
                        '{% extends "three.html" %}{% block content %}{{ block.super }} locmem-three{% endblock %}'
                    ),
                }
            ), 'django.template.loaders.filesystem.Loader'],
        )
        template = engine.get_template('one.html')
        output = template.render(Context({}))
        self.assertEqual(output.strip(), 'three locmem-three two locmem-two one locmem-one') 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:test_extends.py

示例9: test_unique_history_per_loader

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def test_unique_history_per_loader(self):
        """
        Extending should continue even if two loaders return the same
        name for a template.
        """
        engine = Engine(
            loaders=[
                ['django.template.loaders.locmem.Loader', {
                    'base.html': '{% extends "base.html" %}{% block content %}{{ block.super }} loader1{% endblock %}',
                }],
                ['django.template.loaders.locmem.Loader', {
                    'base.html': '{% block content %}loader2{% endblock %}',
                }],
            ]
        )
        template = engine.get_template('base.html')
        output = template.render(Context({}))
        self.assertEqual(output.strip(), 'loader2 loader1') 
开发者ID:nesdis,项目名称:djongo,代码行数:20,代码来源:test_extends.py

示例10: test_block_override_in_extended_included_template

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def test_block_override_in_extended_included_template(self):
        """
        ExtendsNode.find_template() initializes history with self.origin
        (#28071).
        """
        engine = Engine(
            loaders=[
                ['django.template.loaders.locmem.Loader', {
                    'base.html': "{% extends 'base.html' %}{% block base %}{{ block.super }}2{% endblock %}",
                    'included.html':
                        "{% extends 'included.html' %}{% block included %}{{ block.super }}B{% endblock %}",
                }],
                ['django.template.loaders.locmem.Loader', {
                    'base.html': "{% block base %}1{% endblock %}{% include 'included.html' %}",
                    'included.html': "{% block included %}A{% endblock %}",
                }],
            ],
        )
        template = engine.get_template('base.html')
        self.assertEqual(template.render(Context({})), '12AB') 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:test_extends.py

示例11: render_javascript_catalog

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def render_javascript_catalog(catalog=None, plural=None):
    template = Engine().from_string(js_catalog_template)
    indent = lambda s: s.replace('\n', '\n  ')
    context = Context({
        'catalog_str': indent(json.dumps(
            catalog, sort_keys=True, indent=2)) if catalog else None,
        'formats_str': indent(json.dumps(
            get_formats(), sort_keys=True, indent=2)),
        'plural': plural,
    })

    return http.HttpResponse(template.render(context), 'text/javascript') 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:14,代码来源:i18n.py

示例12: csrf_failure

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def csrf_failure(request, reason=""):
    """
    Default view used when request fails CSRF protection
    """
    from django.middleware.csrf import REASON_NO_REFERER, REASON_NO_CSRF_COOKIE
    t = Engine().from_string(CSRF_FAILURE_TEMPLATE)
    c = Context({
        'title': _("Forbidden"),
        'main': _("CSRF verification failed. Request aborted."),
        'reason': reason,
        'no_referer': reason == REASON_NO_REFERER,
        'no_referer1': _(
            "You are seeing this message because this HTTPS site requires a "
            "'Referer header' to be sent by your Web browser, but none was "
            "sent. This header is required for security reasons, to ensure "
            "that your browser is not being hijacked by third parties."),
        'no_referer2': _(
            "If you have configured your browser to disable 'Referer' headers, "
            "please re-enable them, at least for this site, or for HTTPS "
            "connections, or for 'same-origin' requests."),
        'no_cookie': reason == REASON_NO_CSRF_COOKIE,
        'no_cookie1': _(
            "You are seeing this message because this site requires a CSRF "
            "cookie when submitting forms. This cookie is required for "
            "security reasons, to ensure that your browser is not being "
            "hijacked by third parties."),
        'no_cookie2': _(
            "If you have configured your browser to disable cookies, please "
            "re-enable them, at least for this site, or for 'same-origin' "
            "requests."),
        'DEBUG': settings.DEBUG,
        'docs_version': get_docs_version(),
        'more': _("More information is available with DEBUG=True."),
    })
    return HttpResponseForbidden(t.render(c), content_type='text/html') 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:37,代码来源:csrf.py

示例13: render

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def render(self):
        """Render the summary."""
        engine = Engine()
        return engine.from_string(SUMMARY_TEMPLATE).render(Context(self.__dict__)) 
开发者ID:adamalton,项目名称:django-csp-reports,代码行数:6,代码来源:summary.py

示例14: render_javascript_catalog

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def render_javascript_catalog(catalog=None, plural=None):
    template = Engine().from_string(js_catalog_template)

    def indent(s):
        return s.replace('\n', '\n  ')

    context = Context({
        'catalog_str': indent(json.dumps(
            catalog, sort_keys=True, indent=2)) if catalog else None,
        'formats_str': indent(json.dumps(
            get_formats(), sort_keys=True, indent=2)),
        'plural': plural,
    })

    return HttpResponse(template.render(context), 'text/javascript') 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:17,代码来源:i18n.py

示例15: render_to_response

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Engine [as 别名]
def render_to_response(self, context, **response_kwargs):
        def indent(s):
            return s.replace('\n', '\n  ')

        template = Engine().from_string(js_catalog_template)
        context['catalog_str'] = indent(
            json.dumps(context['catalog'], sort_keys=True, indent=2)
        ) if context['catalog'] else None
        context['formats_str'] = indent(json.dumps(context['formats'], sort_keys=True, indent=2))

        return HttpResponse(template.render(Context(context)), 'text/javascript') 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:i18n.py


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