Python django.template 模块,engines() 实例源码

我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用django.template.engines()

项目:django-popup-view-field    作者:djk2    | 项目源码 | 文件源码
def test_django_popup_view_field_javascript(self):

        template_code = """
            {% load django_popup_view_field_tags %}
            {% django_popup_view_field_javascript %}
        """

        template = engines['django'].from_string(template_code)
        html = template.render({})

        self.assertInHTML('''<script type="text/javascript" src="/django_popup_view_field/jsi18n/"></script>''', html)
        self.assertInHTML('''
            <script type="text/javascript" src="/static/django_popup_view_field/js/django_popup_view_field.min.js">
            </script>
        ''', html)
        assert html.find('''id="template-django-popup-view-field"''') != -1
项目:Wagtail-Image-Folders    作者:anteatersa    | 项目源码 | 文件源码
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()
项目:django-filer-celery    作者:nephila    | 项目源码 | 文件源码
def test_get_thumbnail_lazy(self):
        self.create_thumbnail_options()

        base_image = self.create_filer_image_object()
        context = {
            'image': base_image
        }
        request = self.get_request(page=None, lang='en', path='/')
        template = (
            '{% load filer_celery %}\n'
            '{% generate_thumbnail image size="20x20" '
            'crop=True subject_location=image.subject_location as image_big %}\n'
            '{% generate_thumbnail image size="100x20" '
            'crop=False subject_location=image.subject_location %}\n'
            '{% generate_thumbnail image alias="1" '
            'subject_location=image.subject_location%}\n'
            '-{{ image_big.url }}-'
        )
        template_obj = engines['django'].from_string(template)
        output_first_pass = template_obj.render(context, request)
        output_second_pass = template_obj.render(context, request)
        opts = (
            {'size': (20, 20), 'crop': True},
            {'size': (100, 20), 'crop': False},
        )
        self.assertFalse(output_first_pass == output_second_pass)
        for opt in opts:
            existing = get_thumbnailer(base_image).get_existing_thumbnail(opt)
            self.assertTrue(existing)
            self.assertTrue(os.path.exists(existing.path))
            self.assertTrue(output_second_pass.find(existing.url) > -1)

            opt['quality'] = 10
            existing = get_thumbnailer(base_image).get_existing_thumbnail(opt)
            self.assertTrue(existing)
            self.assertTrue(os.path.exists(existing.path))
            self.assertTrue(output_first_pass.find(existing.url) > -1)
项目:django-bootstrap4    作者:zostera    | 项目源码 | 文件源码
def render_template(text, context=None):
    """
    Create a template ``text`` that first loads bootstrap4.
    """
    template = engines['django'].from_string(text)
    if not context:
        context = {}
    return template.render(context)
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
def _get_template(template_string):
    if __is_18:
        return engines['django'].from_string(template_string)
    else:
        return loader.get_template_from_string(template_string)
项目:intake    作者:codeforamerica    | 项目源码 | 文件源码
def COMPRESS_JINJA2_GET_ENVIRONMENT():
    from django.template import engines
    return engines["jinja"].env


# static files location
项目:pretalx    作者:pretalx    | 项目源码 | 文件源码
def rendered_recording_iframe(self):
        if not (self.recording_url and self.recording_source):
            return
        from django.template import engines
        django_engine = engines['django']
        template = django_engine.from_string('<iframe width="100%" height="380px" src="{{ url }}" frameborder="0" allowfullscreen></iframe>')
        return template.render(context={'url': self.recording_url})
项目:cetusshop    作者:icetusorg    | 项目源码 | 文件源码
def _get_template(template_string):
    if __is_18:
        return engines['django'].from_string(template_string)
    else:
        return loader.get_template_from_string(template_string)
项目:templated-docs    作者:alexmorozov    | 项目源码 | 文件源码
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)
项目:django-bootstrap4    作者:GabrielUlici    | 项目源码 | 文件源码
def render_template(text, context=None):
    """
    Create a template ``text`` that first loads bootstrap4.
    """
    template = engines['django'].from_string(text)
    if not context:
        context = {}
    return template.render(context)
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def render_template_obj(self, template, context, request):
        template_obj = engines['django'].from_string(template)
        return template_obj.render(context, request)
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def get_context():
    if engines is not None:
        context = Context()
        context.template = Template('')
        return context
    else:
        return {}
项目:deb-python-django-compressor    作者:openstack    | 项目源码 | 文件源码
def JINJA2_GET_ENVIRONMENT():
        alias = 'jinja2'
        try:
            from django.template import engines
            return engines[alias].env
        except InvalidTemplateEngineError:
            raise InvalidTemplateEngineError(
                "Could not find config for '{}' "
                "in settings.TEMPLATES. "
                "COMPRESS_JINJA2_GET_ENVIRONMENT() may "
                "need to be defined in settings".format(alias))
        except ImportError:
            return None
项目:organizer    作者:tdfischer    | 项目源码 | 文件源码
def email_activists_preview(self, request, pk=None):
        action_obj = self.get_object()
        serializer = serializers.EmailSerializer(data={
            'subject': request.data.get('subject', None),
            'body': request.data.get('body', None),
            'signups': request.data.get('signups', None)
        })
        if serializer.is_valid():
            templated_body = engines['django'].from_string(serializer.validated_data.get('body'))
            email_template = loader.get_template('email.eml')
            signups = models.Signup.objects.filter(
                action=action_obj,
                pk__in=serializer.validated_data.get('signups')
            )
            s = signups[0]
            cxt = {
                'action': action_obj,
                'signup': s,
                'activist': s.activist
            }
            generated_email = email_template.render({
                'signup': s,
                'body': templated_body.render(cxt)
            })
            return Response({'body': generated_email})
        else:
            return Response({'errors': serializer.errors}, 400)
项目:organizer    作者:tdfischer    | 项目源码 | 文件源码
def email_activists(self, request, pk=None):
        action_obj = self.get_object()
        serializer = serializers.EmailSerializer(data={
            'subject': request.data.get('subject', None),
            'body': request.data.get('body', None),
            'signups': request.data.get('signups', None)
        })
        if serializer.is_valid():
            templated_body = engines['django'].from_string(serializer.validated_data.get('body'))
            email_template = loader.get_template('email.eml')
            signups = models.Signup.objects.filter(
                action=action_obj,
                pk__in=serializer.validated_data.get('signups')
            )
            for s in signups:
                cxt = {
                    'action': action_obj,
                    'signup': s,
                    'activist': s.activist
                }
                generated_email = email_template.render({
                    'signup': s,
                    'body': templated_body.render(cxt)
                })
                email_obj = EmailMessage(
                    subject=serializer.validated_data.get('subject'),
                    body=generated_email,
                    to=[s.activist.email],
                    reply_to=[request.user.email],
                )
                email_obj.encoding = 'utf-8'
                email_obj.send()
            return Response({'body': generated_email})
        else:
            return Response({'errors': serializer.errors}, 400)
项目:USTC-Software-2017    作者:igemsoftware2017    | 项目源码 | 文件源码
def render_notice_message(template, dispatcher, **context):

    engine = engines['notices']
    return engine.from_string(template).render(dict(
        category=dispatcher.category,
        **context))
项目:django-learning    作者:adoggie    | 项目源码 | 文件源码
def render_template(text, context=None):
    """
    Create a template ``text`` that first loads bootstrap3.
    """
    template = engines['django'].from_string(text)
    if not context:
        context = {}
    return template.render(context)
项目:wagtail-personalisation    作者:LabD    | 项目源码 | 文件源码
def render_template(value, **context):
    template = engines['django'].from_string(value)
    request = context.pop('request', None)
    return template.render(context, request)
项目:django-boilerplate    作者:cubope    | 项目源码 | 文件源码
def render_template(text, context=None):
    """
    Create a template ``text`` that first loads boilerplate.
    """
    try:
        template = engines['django'].from_string(text)
    except Exception:
        template = Engine().from_string(text)
    if not context:
        context = {}
    return template.render(context)
项目:social-app-django    作者:python-social-auth    | 项目源码 | 文件源码
def render_template_string(request, html, context=None):
    """Take a template in the form of a string and render it for the
    given context"""
    template = engines['django'].from_string(html)
    return template.render(context=context, request=request)
项目:SSBW    作者:AythaE    | 项目源码 | 文件源码
def render_template(text, context=None):
    """
    Create a template ``text`` that first loads bootstrap4.
    """
    template = engines['django'].from_string(text)
    if not context:
        context = {}
    return template.render(context)
项目:SSBW    作者:AythaE    | 项目源码 | 文件源码
def render_template(text, context=None):
    """
    Create a template ``text`` that first loads bootstrap4.
    """
    template = engines['django'].from_string(text)
    if not context:
        context = {}
    return template.render(context)
项目:SSBW    作者:AythaE    | 项目源码 | 文件源码
def render_template(text, context=None):
    """
    Create a template ``text`` that first loads bootstrap4.
    """
    template = engines['django'].from_string(text)
    if not context:
        context = {}
    return template.render(context)
项目:SSBW    作者:AythaE    | 项目源码 | 文件源码
def render_template(text, context=None):
    """
    Create a template ``text`` that first loads bootstrap4.
    """
    template = engines['django'].from_string(text)
    if not context:
        context = {}
    return template.render(context)
项目:SSBW    作者:AythaE    | 项目源码 | 文件源码
def render_template(text, context=None):
    """
    Create a template ``text`` that first loads bootstrap4.
    """
    template = engines['django'].from_string(text)
    if not context:
        context = {}
    return template.render(context)