本文整理汇总了Python中test_utils.RequestFactory.META方法的典型用法代码示例。如果您正苦于以下问题:Python RequestFactory.META方法的具体用法?Python RequestFactory.META怎么用?Python RequestFactory.META使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test_utils.RequestFactory
的用法示例。
在下文中一共展示了RequestFactory.META方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_email
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import META [as 别名]
def render_email(template, context):
"""Renders a template in the currently set locale."""
req = RequestFactory()
req.META = {}
req.locale = translation.get_language()
return jingo.render_to_string(req, template, context)
示例2: render
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import META [as 别名]
def render(self, name, value, attrs=None):
topics_and_subtopics = Topic.objects.all()
topics = [t for t in topics_and_subtopics if t.parent_id is None]
for topic in topics:
self.process_topic(value, topic)
topic.my_subtopics = [t for t in topics_and_subtopics
if t.parent_id == topic.id]
for subtopic in topic.my_subtopics:
self.process_topic(value, subtopic)
# Create a fake request to make jingo happy.
req = RequestFactory()
req.META = {}
req.locale = settings.WIKI_DEFAULT_LANGUAGE
return jingo.render_to_string(
req,
'wiki/includes/topics_widget.html',
{
'topics': topics,
'name': name,
})
示例3: _render
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import META [as 别名]
def _render(locale):
"""Render an email in the given locale.
Because of safe_translation decorator, if this fails,
the function will be run again in English.
"""
req = RequestFactory()
req.META = {}
req.locale = locale
return jingo.render_to_string(req, template, context)