當前位置: 首頁>>代碼示例>>Python>>正文


Python template.Template方法代碼示例

本文整理匯總了Python中django.template.Template方法的典型用法代碼示例。如果您正苦於以下問題:Python template.Template方法的具體用法?Python template.Template怎麽用?Python template.Template使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.template的用法示例。


在下文中一共展示了template.Template方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: view_email_preview

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def view_email_preview(request, alert_type, alert_id, automation_id):
    alert_email = get_object_or_404(AlertEmailTemplate, id=automation_id)
    alert_type = get_object_or_404(AlertType, slug=alert_type, unit__in=request.units)
    alert = get_object_or_404(Alert, pk=alert_id, alerttype__unit__in=request.units)

    t = Template( alert_email.content )

    email_context = build_context( alert )    
    email_context['details'] = {}
    for k, v in alert.details.items():
        email_context['details'][k] = str(v)

    rendered_text = t.render( Context(email_context) ) 
    
    return render(request, 'alerts/view_email_preview.html', { 'alert_type':alert_type, 
                                                                'alert':alert, 
                                                                'alert_email':alert_email, 
                                                                'rendered_text':rendered_text }) 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:20,代碼來源:views.py

示例2: get

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def get(self, request, object_id):
        model_fields = [f.name for f in self.opts.fields]
        fields = [f for f in request.GET['fields'].split(',') if f in model_fields]
        defaults = {
            "form": self.form,
            "fields": fields,
            "formfield_callback": self.formfield_for_dbfield,
        }
        form_class = modelform_factory(self.model, **defaults)
        form = form_class(instance=self.org_obj)

        helper = FormHelper()
        helper.form_tag = False
        helper.include_media = False
        form.helper = helper

        s = '{% load i18n crispy_forms_tags %}<form method="post" action="{{action_url}}">{% crispy form %}' + \
            '<button type="submit" class="btn btn-success btn-block btn-sm">{% trans "Apply" %}</button></form>'
        t = template.Template(s)
        c = template.Context({'form': form, 'action_url': self.model_admin_url('patch', self.org_obj.pk)})

        return HttpResponse(t.render(c)) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:24,代碼來源:editable.py

示例3: test_preferences_cp

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def test_preferences_cp(self):
        request = RequestFactory().get('/')
        context = context_processors.preferences_cp(request)

        # context should have preferences.
        my_preferences = context['preferences']

        # preferences should have test MyPreferences object member.
        my_preferences = my_preferences.MyPreferences
        self.failUnless(isinstance(my_preferences, MyPreferences),
                        "%s should be instance of MyPreferences." % my_preferences)

        # With preferences_cp is loaded as a TEMPLATE_CONTEXT_PROCESSORS
        # templates should have access to preferences object.
        context_instance = RequestContext(request)
        t = Template("{% if preferences %}{{ preferences }}{% endif %}")
        self.failUnless(t.render(context_instance), "preferences should be \
available in template context.")

        t = Template("{% if preferences.MyPreferences %}{{ \
preferences.MyPreferences }}{% endif %}")
        self.failUnless(t.render(context_instance), "MyPreferences should be \
available as part of preferences var in template context.") 
開發者ID:82Flex,項目名稱:DCRM,代碼行數:25,代碼來源:test_all.py

示例4: get_template

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def get_template(self, template_name, skip=None):
        """
        Call self.get_template_sources() and return a Template object for
        the first template matching template_name. If skip is provided, ignore
        template origins in skip. This is used to avoid recursion during
        template extending.
        """
        tried = []

        for origin in self.get_template_sources(template_name):
            if skip is not None and origin in skip:
                tried.append((origin, 'Skipped'))
                continue

            try:
                contents = self.get_contents(origin)
            except TemplateDoesNotExist:
                tried.append((origin, 'Source does not exist'))
                continue
            else:
                return Template(
                    contents, origin, origin.template_name, self.engine,
                )

        raise TemplateDoesNotExist(template_name, tried=tried) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:27,代碼來源:base.py

示例5: test_add_to_builtins

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def test_add_to_builtins(self):
            from compat import add_to_builtins

            # Explicit import of tags
            template = Template(
                '{% load test_app_tags %}'
                '{% my_tag %}'
            )
            self.assertIn('Return value of my_tag', template.render(Context({})))

            # No import
            with self.assertRaises(TemplateSyntaxError):
                template = Template(
                    '{% my_tag %}'
                )
                template.render(Context({}))

            # No import but add_to_builtins call
            add_to_builtins('compat.tests.test_app.templatetags.test_app_tags')
            template = Template(
                '{% my_tag %}'
            )
            self.assertIn('Return value of my_tag', template.render(Context({}))) 
開發者ID:arteria,項目名稱:django-compat,代碼行數:25,代碼來源:test_compat.py

示例6: test_get_connection_distance

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def test_get_connection_distance(self):
        tpl = """{%% spaceless %%}
            {%% load connections %%}
            {%% get_connection_distance %s foo bar as distance %%}
            {{ distance }}
        {%% endspaceless %%}"""
        
        create_connection(self.r, self.foo, self.bar)
        
        assert '1' == Template(tpl % "'user_follow'").render(Context({
            'foo': self.foo,
            'bar': self.bar,
        }))
        
        assert '1' == Template(tpl % "rel").render(Context({
            'rel': self.r,
            'foo': self.foo,
            'bar': self.bar,
        })) 
開發者ID:dfunckt,項目名稱:django-connections,代碼行數:21,代碼來源:test_templatetags.py

示例7: test_connections_from_object

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def test_connections_from_object(self):
        tpl = """{%% spaceless %%}
            {%% load connections %%}
            {%% connections_from_object %s foo as connections %%}
            {%% for c in connections %%}{{ c.to_object.username }}, {%% endfor %%}
        {%% endspaceless %%}"""
        
        create_connection(self.r, self.foo, self.bar)
        create_connection(self.r, self.foo, self.jaz)
        
        assert 'bar, jaz,' == Template(tpl % "'user_follow'").render(Context({
            'foo': self.foo,
        }))
        
        assert 'bar, jaz,' == Template(tpl % "rel").render(Context({
            'rel': self.r,
            'foo': self.foo,
        })) 
開發者ID:dfunckt,項目名稱:django-connections,代碼行數:20,代碼來源:test_templatetags.py

示例8: test_connections_to_object

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def test_connections_to_object(self):
        tpl = """{%% spaceless %%}
            {%% load connections %%}
            {%% connections_to_object %s foo as connections %%}
            {%% for c in connections %%}{{ c.from_object.username }}, {%% endfor %%}
        {%% endspaceless %%}"""
        
        create_connection(self.r, self.bar, self.foo)
        create_connection(self.r, self.jaz, self.foo)
        
        assert 'bar, jaz,' == Template(tpl % "'user_follow'").render(Context({
            'foo': self.foo,
        }))
        
        assert 'bar, jaz,' == Template(tpl % "rel").render(Context({
            'rel': self.r,
            'foo': self.foo,
        })) 
開發者ID:dfunckt,項目名稱:django-connections,代碼行數:20,代碼來源:test_templatetags.py

示例9: test_connection_exists

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def test_connection_exists(self):
        tpl = """{%% spaceless %%}
            {%% load connections %%}
            {%% connection_exists %s foo bar as has_connection %%}
            {{ has_connection|yesno:'True,False' }}
        {%% endspaceless %%}"""
        
        create_connection(self.r, self.foo, self.bar)
        
        assert 'True' == Template(tpl % "'user_follow'").render(Context({
            'foo': self.foo,
            'bar': self.bar,
        }))
        
        assert 'True' == Template(tpl % "rel").render(Context({
            'rel': self.r,
            'foo': self.foo,
            'bar': self.bar,
        })) 
開發者ID:dfunckt,項目名稱:django-connections,代碼行數:21,代碼來源:test_templatetags.py

示例10: write_response

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def write_response(self, response):
        if isinstance(response, RedirectResponse):
            result = HttpResponseRedirect(response.url, status=response.status)
        elif isinstance(response, OptionalJSONResponse) and isinstance(response.data, HttpResponseBase):
            result = response.data
        elif isinstance(response, TemplateResponse):
            template_path = os.path.join(base_settings.BASE_DIR, 'templates', response.template)
            with open(template_path, 'r') as file:
                template = file.read()
                template = template.replace('{% end %}', '{% endif %}')
                context = Context(response.data)
                content = Template(template).render(context)
                result = HttpResponse(content, status=response.status)
        else:
            result = HttpResponse(response.render(), status=response.status)

        for name, value in self.view.default_headers().items():
            result[name] = value

        for name, value in response.header_items():
            result[name] = value

        return result 
開發者ID:jet-admin,項目名稱:jet-bridge,代碼行數:25,代碼來源:route_view.py

示例11: render_template

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def render_template(request, order_id=None):
    """
    Renders the template with this title with the current
    Service Order as the context
    """
    title = request.POST.get('title')
    tpl = get_object_or_404(Template, title=title)
    content = tpl.content

    if order_id:
        order = get_object_or_404(Order, pk=order_id)
        content = tpl.render(order)

    return HttpResponse(content) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:16,代碼來源:note.py

示例12: templates

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def templates(request, template_id=None):
    if template_id:
        tpl = get_object_or_404(Template, pk=template_id)
        content = tpl.content
        if request.session.get('current_order_id'):
            tpl = template.Template(content)
            order = Order.objects.get(pk=request.session['current_order_id'])
            content = tpl.render(template.Context({'order': order}))

        return HttpResponse(content)

    templates = Template.objects.all()
    return render(request, 'notes/templates.html', {'templates': templates}) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:15,代碼來源:note.py

示例13: clean_content

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def clean_content(self):
        content = self.cleaned_data.get('content')
        try:
            template.Template(content)
        except template.TemplateSyntaxError, e:
            raise forms.ValidationError(_('Syntax error in template: %s') % e) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:8,代碼來源:admin.py

示例14: templates

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def templates(self):
        choices = Template.objects.all().values_list('title', flat=True)
        return list(choices) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:5,代碼來源:common.py

示例15: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import Template [as 別名]
def render(self, context):
        from django import template
        tpl = template.Template(self.content)
        return tpl.render(template.Context({'order': context})) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:6,代碼來源:common.py


注:本文中的django.template.Template方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。