本文整理汇总了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
示例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
示例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)
示例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}))
示例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)
示例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()
示例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)