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


Python template.engines方法代码示例

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


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

示例1: setUp

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def setUp(self):
        super(TestMMVHTMLRenderer, self).setUp()

        """
        Monkeypatch get_template
        Taken from DRF Tests
        """
        self.get_template = django.template.loader.get_template

        def get_template(template_name, dirs=None):
            if template_name == 'test.html':
                return engines['django'].from_string("<html>test: {{ data }}</html>")
            raise TemplateDoesNotExist(template_name)

        def select_template(template_name_list, dirs=None, using=None):
            if template_name_list == ['test.html']:
                return engines['django'].from_string("<html>test: {{ data }}</html>")
            raise TemplateDoesNotExist(template_name_list[0])

        django.template.loader.get_template = get_template
        django.template.loader.select_template = select_template 
开发者ID:MattBroach,项目名称:DjangoRestMultipleModels,代码行数:23,代码来源:test_html_renderer.py

示例2: setUp

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def setUp(self):
        self.engine = engines['jinja2']

        self.image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )

        # Create an image with a missing file, by deserializing fom a python object
        # (which bypasses FileField's attempt to read the file)
        self.bad_image = list(serializers.deserialize('python', [{
            'fields': {
                'title': 'missing image',
                'height': 100,
                'file': 'original_images/missing-image.jpg',
                'width': 100,
            },
            'model': 'wagtailimages.image'
        }]))[0].object
        self.bad_image.save() 
开发者ID:wagtail,项目名称:wagtail,代码行数:22,代码来源:test_jinja2.py

示例3: test_full_dec_templateresponse

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def test_full_dec_templateresponse(self):
        """
        All methods of middleware are called for TemplateResponses in
        the right sequence.
        """
        @full_dec
        def template_response_view(request):
            template = engines['django'].from_string("Hello world")
            return TemplateResponse(request, template)

        request = self.rf.get('/')
        response = template_response_view(request)
        self.assertTrue(getattr(request, 'process_request_reached', False))
        self.assertTrue(getattr(request, 'process_view_reached', False))
        self.assertTrue(getattr(request, 'process_template_response_reached', False))
        # response must not be rendered yet.
        self.assertFalse(response._is_rendered)
        # process_response must not be called until after response is rendered,
        # otherwise some decorators like csrf_protect and gzip_page will not
        # work correctly. See #16004
        self.assertFalse(getattr(request, 'process_response_reached', False))
        response.render()
        self.assertTrue(getattr(request, 'process_response_reached', False))
        # process_response saw the rendered content
        self.assertEqual(request.process_response_content, b"Hello world") 
开发者ID:nesdis,项目名称:djongo,代码行数:27,代码来源:test_decorators.py

示例4: test_patch_vary_headers

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def test_patch_vary_headers(self):
        headers = (
            # Initial vary, new headers, resulting vary.
            (None, ('Accept-Encoding',), 'Accept-Encoding'),
            ('Accept-Encoding', ('accept-encoding',), 'Accept-Encoding'),
            ('Accept-Encoding', ('ACCEPT-ENCODING',), 'Accept-Encoding'),
            ('Cookie', ('Accept-Encoding',), 'Cookie, Accept-Encoding'),
            ('Cookie, Accept-Encoding', ('Accept-Encoding',), 'Cookie, Accept-Encoding'),
            ('Cookie, Accept-Encoding', ('Accept-Encoding', 'cookie'), 'Cookie, Accept-Encoding'),
            (None, ('Accept-Encoding', 'COOKIE'), 'Accept-Encoding, COOKIE'),
            ('Cookie,     Accept-Encoding', ('Accept-Encoding', 'cookie'), 'Cookie, Accept-Encoding'),
            ('Cookie    ,     Accept-Encoding', ('Accept-Encoding', 'cookie'), 'Cookie, Accept-Encoding'),
        )
        for initial_vary, newheaders, resulting_vary in headers:
            with self.subTest(initial_vary=initial_vary, newheaders=newheaders):
                template = engines['django'].from_string("This is a test")
                response = TemplateResponse(HttpRequest(), template)
                if initial_vary is not None:
                    response['Vary'] = initial_vary
                patch_vary_headers(response, newheaders)
                self.assertEqual(response['Vary'], resulting_vary) 
开发者ID:nesdis,项目名称:djongo,代码行数:23,代码来源:tests.py

示例5: test_get_cache_key

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def test_get_cache_key(self):
        request = self.factory.get(self.path)
        template = engines['django'].from_string("This is a test")
        response = TemplateResponse(HttpRequest(), template)
        key_prefix = 'localprefix'
        # Expect None if no headers have been set yet.
        self.assertIsNone(get_cache_key(request))
        # Set headers to an empty list.
        learn_cache_key(request, response)

        self.assertEqual(
            get_cache_key(request),
            'views.decorators.cache.cache_page.settingsprefix.GET.'
            '58a0a05c8a5620f813686ff969c26853.d41d8cd98f00b204e9800998ecf8427e'
        )
        # A specified key_prefix is taken into account.
        learn_cache_key(request, response, key_prefix=key_prefix)
        self.assertEqual(
            get_cache_key(request, key_prefix=key_prefix),
            'views.decorators.cache.cache_page.localprefix.GET.'
            '58a0a05c8a5620f813686ff969c26853.d41d8cd98f00b204e9800998ecf8427e'
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:24,代码来源:tests.py

示例6: _get_template_loaders

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def _get_template_loaders():
    """
    Get all available template loaders for the Django engine.
    """
    loaders = []

    for loader_name in engines['django'].engine.loaders:
        loader = engines['django'].engine.find_template_loader(loader_name)
        if loader is not None and hasattr(loader, 'get_template_sources'):
            loaders.append(loader)
    return tuple(loaders) 
开发者ID:alexmorozov,项目名称:templated-docs,代码行数:13,代码来源:__init__.py

示例7: render_template

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def render_template(value, **context):
    template = engines["django"].from_string(value)
    request = context.pop("request", None)
    return template.render(context, request) 
开发者ID:jberghoef,项目名称:wagtail-tag-manager,代码行数:6,代码来源:utils.py

示例8: test_get_last_invalidation_jinja2

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def test_get_last_invalidation_jinja2(self):
        original_timestamp = engines['jinja2'].from_string(
            "{{ timestamp }}"
        ).render({
            'timestamp': get_last_invalidation('auth.Group', 'cachalot_test'),
        })
        template = engines['jinja2'].from_string(
            "{{ get_last_invalidation('auth.Group', 'cachalot_test') }}")
        timestamp = template.render({})

        self.assertNotEqual(timestamp, '')
        self.assertNotEqual(timestamp, '0.0')
        self.assertAlmostEqual(float(timestamp), float(original_timestamp),
                               delta=0.1) 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:16,代码来源:api.py

示例9: render_template

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def render_template(value, **context):
    template = engines['django'].from_string(value)
    request = context.pop('request', None)
    return template.render(context, request) 
开发者ID:wagtail,项目名称:wagtail-personalisation,代码行数:6,代码来源:utils.py

示例10: render_template

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def render_template(self, template_string, context={}, using='tex'):
        engine = engines[using]
        template = engine.from_string(template_string)
        return template.render(context) 
开发者ID:weinbusch,项目名称:django-tex,代码行数:6,代码来源:tests.py

示例11: setUp

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def setUp(self):
        self.engine = engines['jinja2']

        self.user = get_user_model().objects.create_superuser(
            username='test',
            email='test@email.com',
            password='password'
        )
        self.homepage = Page.objects.get(id=2) 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:test_jinja2.py

示例12: setUp

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def setUp(self):
        super().setUp()
        self.engine = engines['jinja2'] 
开发者ID:wagtail,项目名称:wagtail,代码行数:5,代码来源:test_templates.py

示例13: setUp

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def setUp(self):
        self.engine = engines['jinja2'] 
开发者ID:wagtail,项目名称:wagtail,代码行数:4,代码来源:test_jinja2.py

示例14: COMPRESS_JINJA2_GET_ENVIRONMENT

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def COMPRESS_JINJA2_GET_ENVIRONMENT():
    from django.template import engines
    return engines["jinja"].env 
开发者ID:codeforamerica,项目名称:intake,代码行数:5,代码来源:base.py

示例15: template

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import engines [as 别名]
def template(request):
    template = engines["django"].from_string(
        "Hello {% block name %}{{ name }}{% endblock %}!"
    )
    context = {"name": "World"}
    return HttpResponse(template.render(context)) 
开发者ID:scoutapp,项目名称:scout_apm_python,代码行数:8,代码来源:django_app.py


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