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


Python template.render方法代碼示例

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


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

示例1: bootstrap_horizontal

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def bootstrap_horizontal(element, label_cols='col-sm-2 col-lg-2'):

    markup_classes = {'label': label_cols, 'value': '', 'single_value': ''}

    for cl in label_cols.split(' '):
        splitted_class = cl.split('-')

        try:
            value_nb_cols = int(splitted_class[-1])
        except ValueError:
            value_nb_cols = config.BOOTSTRAP_COLUMN_COUNT

        if value_nb_cols >= config.BOOTSTRAP_COLUMN_COUNT:
            splitted_class[-1] = config.BOOTSTRAP_COLUMN_COUNT
        else:
            offset_class = cl.split('-')
            offset_class[-1] = 'offset-' + str(value_nb_cols)
            splitted_class[-1] = str(config.BOOTSTRAP_COLUMN_COUNT - value_nb_cols)
            markup_classes['single_value'] += ' ' + '-'.join(offset_class)
            markup_classes['single_value'] += ' ' + '-'.join(splitted_class)

        markup_classes['value'] += ' ' + '-'.join(splitted_class)

    return render(element, markup_classes) 
開發者ID:OpenMDM,項目名稱:OpenMDM,代碼行數:26,代碼來源:bootstrap.py

示例2: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def render(element, markup_classes):
    element_type = element.__class__.__name__.lower()

    if element_type == 'boundfield':
        add_input_classes(element)
        template = get_template("bootstrapform/field.html")
        context = Context({'field': element, 'classes': markup_classes, 'form': element.form})
    else:
        has_management = getattr(element, 'management_form', None)
        if has_management:
            for form in element.forms:
                for field in form.visible_fields():
                    add_input_classes(field)

            template = get_template("bootstrapform/formset.html")
            context = Context({'formset': element, 'classes': markup_classes})
        else:
            for field in element.visible_fields():
                add_input_classes(field)

            template = get_template("bootstrapform/form.html")
            context = Context({'form': element, 'classes': markup_classes})

    return template.render(context) 
開發者ID:OpenMDM,項目名稱:OpenMDM,代碼行數:26,代碼來源:bootstrap.py

示例3: as_bootstrap_inline

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def as_bootstrap_inline(form):
    template = get_template("bootstrap/form.html")
    form = _preprocess_fields(form)

    for field in form.fields:
        name = form.fields[field].widget.__class__.__name__.lower()
        if not name.startswith("radio") and not name.startswith("checkbox"):
            form.fields[field].widget.attrs["placeholder"] = form.fields[field].label
    css_classes = {
        "label": "sr-only",
        "single_container": "",
        "wrap": "",
    }
    context = {
        "form": form,
        "css_classes": css_classes,
    }
    return template.render(contex) 
開發者ID:mgaitan,項目名稱:waliki,代碼行數:20,代碼來源:bootstrap_tags.py

示例4: run

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def run(engines, number=2000, verbose=False):
    basepath = os.path.abspath(os.path.dirname(__file__))
    for engine in engines:
        dirname = os.path.join(basepath, engine)
        if verbose:
            print('%s:' % engine.capitalize())
            print('--------------------------------------------------------')
        else:
            sys.stdout.write('%s:' % engine.capitalize())
        t = timeit.Timer(setup='from __main__ import %s; render = %s(r"%s", %s)'
                                       % (engine, engine, dirname, verbose),
                                 stmt='render()')

        time = t.timeit(number=number) / number
        if verbose:
            print('--------------------------------------------------------')
        print('%.2f ms' % (1000 * time))
        if verbose:
            print('--------------------------------------------------------') 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:21,代碼來源:basic.py

示例5: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def render(template_path, template_dict, debug=False):
  """Renders the template at the given path with the given dict of values.

  Example usage:
    render("templates/index.html", {"name": "Bret", "values": [1, 2, 3]})

  Args:
    template_path: path to a Django template
    template_dict: dictionary of values to apply to the template

  Returns:
    The rendered template as a string.
  """
  if os.environ.get('APPENGINE_RUNTIME') == 'python27':
    warnings.warn(_PYTHON27_DEPRECATION, DeprecationWarning, stacklevel=2)
    t = _load_internal_django(template_path, debug)
  else:
    t = _load_user_django(template_path, debug)
  return t.render(Context(template_dict)) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:21,代碼來源:template.py

示例6: render

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def render(self, context):
        template = self.template.resolve(context)
        # Does this quack like a Template?
        if not callable(getattr(template, 'render', None)):
            # If not, we'll try our cache, and get_template()
            template_name = template
            cache = context.render_context.dicts[0].setdefault(self, {})
            template = cache.get(template_name)
            if template is None:
                template = context.template.engine.get_template(template_name)
                cache[template_name] = template
        # Use the base.Template of a backends.django.Template.
        elif hasattr(template, 'template'):
            template = template.template
        values = {
            name: var.resolve(context)
            for name, var in self.extra_context.items()
        }
        with context.push(**values):
            return template.render(context) 
開發者ID:matllubos,項目名稱:django-is-core,代碼行數:22,代碼來源:forms.py

示例7: get_rendered

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def get_rendered(name, lang, extra_key=None,
                 get_vars=lambda: {}, cache_seconds=1, bundle_name=None):
    """Gets the rendered content of a Resource from the cache or the datastore.
    If name is 'foo.html', this looks for a Resource named 'foo.html' to serve
    as a plain file, then a Resource named 'foo.html.template' to render as a
    template.  Returns None if nothing suitable is found.  When rendering a
    template, this calls get_vars() to obtain a dictionary of template
    variables.  The cache is keyed on bundle_name, name, lang, and extra_key;
    use extra_key to capture dependencies on template variables)."""
    bundle_name = bundle_name or active_bundle_name
    cache_key = (bundle_name, name, lang, extra_key)
    content = RENDERED_CACHE.get(cache_key)
    if content is None:
        resource = get_localized(name, lang, bundle_name)
        if resource:  # a plain file is available
            return resource.content  # already cached, no need to cache again
        resource = get_localized(name + '.template', lang, bundle_name)
        if resource:  # a template is available
            content = render_in_lang(resource.get_template(), lang, get_vars())
            RENDERED_CACHE.put(cache_key, content, cache_seconds)
    return content 
開發者ID:google,項目名稱:personfinder,代碼行數:23,代碼來源:resources.py

示例8: bootstrap

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def bootstrap(element):
    markup_classes = {'label': '', 'value': '', 'single_value': ''}
    return render(element, markup_classes) 
開發者ID:OpenMDM,項目名稱:OpenMDM,代碼行數:5,代碼來源:bootstrap.py

示例9: bootstrap_inline

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def bootstrap_inline(element):
    markup_classes = {'label': 'sr-only', 'value': '', 'single_value': ''}
    return render(element, markup_classes) 
開發者ID:OpenMDM,項目名稱:OpenMDM,代碼行數:5,代碼來源:bootstrap.py

示例10: display

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def display(self, request, correlated=False, json=False):
        context = RequestContext(request)
        template = get_template(self.__class__.template)
        context['artifact_name'] = self.__class__.display_name
        if correlated:
            context['artifact_values'] = self._correlated
        else:
            context['artifact_values'] = self._artifacts

        context['event'] = self._event

        if not json:
            return template.render(context.flatten(), request)
        else:
            return context.flatten() 
開發者ID:certsocietegenerale,項目名稱:FIR,代碼行數:17,代碼來源:artifacts.py

示例11: render_form

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def render_form(form):
    """same than  {{ form|crispy }} if crispy_forms is installed.
    render using a bootstrap3 templating otherwise"""

    if 'crispy_forms' in settings.INSTALLED_APPS:
        from crispy_forms.templatetags.crispy_forms_filters import as_crispy_form
        return as_crispy_form(form)

    template = get_template("bootstrap/form.html")
    form = _preprocess_fields(form)

    return template.render({"form": form}) 
開發者ID:mgaitan,項目名稱:waliki,代碼行數:14,代碼來源:bootstrap_tags.py

示例12: as_bootstrap_horizontal

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def as_bootstrap_horizontal(form, label_classes=""):
    template = get_template("bootstrap/form.html")
    form = _preprocess_fields(form)

    if label_classes == "":
        label_classes = "col-md-2"

    css_classes = {
        "label": label_classes,
        "single_container": "",
        "wrap": "",
    }

    for label_class in label_classes.split(" "):
        split_class, column_count = label_class.rsplit("-", 1)
        column_count = int(column_count)

        if column_count < 12:
            offset_class = "{split_class}-offset-{column_count}".format(
                split_class=split_class,
                column_count=column_count,
            )
            wrap_class = "{split_class}-{column_count}".format(
                split_class=split_class,
                column_count=12 - column_count,
            )
            css_classes["single_container"] += offset_class + " " + wrap_class + " "
            css_classes["wrap"] += wrap_class + " "
    context = {
        "form": form,
        "css_classes": css_classes,
    }
    return template.render(context) 
開發者ID:mgaitan,項目名稱:waliki,代碼行數:35,代碼來源:bootstrap_tags.py

示例13: paginate_links

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def paginate_links(page, request, with_canonical=False):
    canonical = prev_page_url = next_page_url = None
    current_url = furl(request.get_full_path() if request else '')

    if with_canonical:
        if current_url.args.get('page') == '1':
            del current_url.args['page']
        canonical = current_url.url

    if page.has_previous():
        prev_page_url = _get_url_with_page_num(
            current_url, page.previous_page_number())
        if request:
            prev_page_url = request.build_absolute_uri(prev_page_url)

    if page.has_next():
        next_page_url = _get_url_with_page_num(
            current_url, page.next_page_number())
        if request:
            next_page_url = request.build_absolute_uri(next_page_url)

    context = {
        'page': page,
        'canonical': canonical,
        'base_url': request.build_absolute_uri(request.path),
        'prev_page_url': prev_page_url,
        'next_page_url': next_page_url,
    }
    template = loader.get_template('django_rangepaginator/link_tags.html')
    return template.render(context) 
開發者ID:mvantellingen,項目名稱:django-rangepaginator,代碼行數:32,代碼來源:rangepaginator.py

示例14: genshi

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def genshi(dirname, verbose=False):
    from genshi.template import TemplateLoader
    loader = TemplateLoader([dirname], auto_reload=False)
    template = loader.load('template.html')
    def render():
        data = dict(title=TITLE, user=USER, items=ITEMS)
        return template.generate(**data).render('xhtml')

    if verbose:
        print(render())
    return render 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:13,代碼來源:basic.py

示例15: myghty

# 需要導入模塊: from django import template [as 別名]
# 或者: from django.template import render [as 別名]
def myghty(dirname, verbose=False):
    from myghty import interp
    interpreter = interp.Interpreter(component_root=dirname)
    def render():
        data = dict(title=TITLE, user=USER, items=ITEMS)
        buffer = StringIO()
        interpreter.execute("template.myt", request_args=data, out_buffer=buffer)
        return buffer.getvalue()
    if verbose:
        print(render())
    return render 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:13,代碼來源:basic.py


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