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


Python context.make_context方法代码示例

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


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

示例1: test_wtm_include_necessary

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import make_context [as 别名]
def test_wtm_include_necessary(rf, site):
    expected_result = '<link href="/static/test.css" rel="stylesheet" type="text/css"/>'

    token = Token(token_type=TOKEN_TYPE, contents='wtm_include "necessary" "test.css"')
    parser = Parser(tokens=[token])
    node = wtm_include(parser, token)

    request = rf.get(site.root_page.url)
    result = node.render(context=make_context({"request": request}))

    assert result == expected_result

    request.COOKIES = {"wtm": "necessary:false"}
    result = node.render(context=make_context({"request": request}))

    assert result == expected_result

    request.COOKIES = {"wtm": "necessary:true"}
    result = node.render(context=make_context({"request": request}))

    assert result == expected_result 
开发者ID:jberghoef,项目名称:wagtail-tag-manager,代码行数:23,代码来源:test_templatetags.py

示例2: test_wtm_include_preferences

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import make_context [as 别名]
def test_wtm_include_preferences(rf, site):
    expected_result = '<script src="/static/test.js" type="text/javascript"></script>'

    token = Token(token_type=TOKEN_TYPE, contents='wtm_include "preferences" "test.js"')
    parser = Parser(tokens=[token])
    node = wtm_include(parser, token)

    request = rf.get(site.root_page.url)
    result = node.render(context=make_context({"request": request}))

    assert result == expected_result

    request.COOKIES = {"wtm": "preferences:false"}
    result = node.render(context=make_context({"request": request}))

    assert result == ""

    request.COOKIES = {"wtm": "preferences:true"}
    result = node.render(context=make_context({"request": request}))

    assert result == expected_result 
开发者ID:jberghoef,项目名称:wagtail-tag-manager,代码行数:23,代码来源:test_templatetags.py

示例3: render

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import make_context [as 别名]
def render(self, context=None, request=None):
        # A deprecation path is required here to cover the following usage:
        # >>> from django.template import Context
        # >>> from django.template.loader import get_template
        # >>> template = get_template('hello.html')
        # >>> template.render(Context({'name': 'world'}))
        # In Django 1.7 get_template() returned a django.template.Template.
        # In Django 1.8 it returns a django.template.backends.django.Template.
        # In Django 1.10 the isinstance checks should be removed. If passing a
        # Context or a RequestContext works by accident, it won't be an issue
        # per se, but it won't be officially supported either.
        if isinstance(context, RequestContext):
            if request is not None and request is not context.request:
                raise ValueError(
                    "render() was called with a RequestContext and a request "
                    "argument which refer to different requests. Make sure "
                    "that the context argument is a dict or at least that "
                    "the two arguments refer to the same request.")
            warnings.warn(
                "render() must be called with a dict, not a RequestContext.",
                RemovedInDjango110Warning, stacklevel=2)

        elif isinstance(context, Context):
            warnings.warn(
                "render() must be called with a dict, not a Context.",
                RemovedInDjango110Warning, stacklevel=2)

        else:
            context = make_context(context, request)

        return self.template.render(context) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:33,代码来源:django.py

示例4: test_wtm_include_marketing

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import make_context [as 别名]
def test_wtm_include_marketing(rf, site):
    token = Token(token_type=TOKEN_TYPE, contents='wtm_include "marketing" "test.html"')
    parser = Parser(tokens=[token])
    node = wtm_include(parser, token)

    with pytest.raises(TemplateDoesNotExist):
        request = rf.get(site.root_page.url)
        node.render(context=make_context({"request": request}))

        request.COOKIES = {"wtm": "marketing:false"}
        node.render(context=make_context({"request": request}))

        request.COOKIES = {"wtm": "marketing:true"}
        node.render(context=make_context({"request": request})) 
开发者ID:jberghoef,项目名称:wagtail-tag-manager,代码行数:16,代码来源:test_templatetags.py

示例5: render

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import make_context [as 别名]
def render(self, context=None, request=None):
        context = make_context(context, request, autoescape=self.backend.engine.autoescape)
        try:
            return self.template.render(context)
        except TemplateDoesNotExist as exc:
            reraise(exc, self.backend) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:8,代码来源:django.py

示例6: render

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import make_context [as 别名]
def render(self):
        context = make_context(self.get_context_data(), request=self.request)
        template = get_template(self.template_name)
        with context.bind_template(template.template):
            blocks = self._get_blocks(template.template.nodelist, context)
            for block_node in blocks.values():
                self._process_block(block_node, context)
        self._attach_body() 
开发者ID:sunscrapers,项目名称:django-templated-mail,代码行数:10,代码来源:mail.py

示例7: render

# 需要导入模块: from django.template import context [as 别名]
# 或者: from django.template.context import make_context [as 别名]
def render(self, context=None, request=None):
        # A deprecation path is required here to cover the following usage:
        # >>> from django.template import Context
        # >>> from django.template.loader import get_template
        # >>> template = get_template('hello.html')
        # >>> template.render(Context({'name': 'world'}))
        # In Django 1.7 get_template() returned a django.template.Template.
        # In Django 1.8 it returns a django.template.backends.django.Template.
        # In Django 1.10 the isinstance checks should be removed. If passing a
        # Context or a RequestContext works by accident, it won't be an issue
        # per se, but it won't be officially supported either.
        if isinstance(context, RequestContext):
            if request is not None and request is not context.request:
                raise ValueError(
                    "render() was called with a RequestContext and a request "
                    "argument which refer to different requests. Make sure "
                    "that the context argument is a dict or at least that "
                    "the two arguments refer to the same request.")
            warnings.warn(
                "render() must be called with a dict, not a RequestContext.",
                RemovedInDjango110Warning, stacklevel=2)

        elif isinstance(context, Context):
            warnings.warn(
                "render() must be called with a dict, not a Context.",
                RemovedInDjango110Warning, stacklevel=2)

        else:
            context = make_context(context, request)

        try:
            return self.template.render(context)
        except TemplateDoesNotExist as exc:
            reraise(exc, self.backend) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:36,代码来源:django.py


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