本文整理汇总了Python中werkzeug.Request.translations方法的典型用法代码示例。如果您正苦于以下问题:Python Request.translations方法的具体用法?Python Request.translations怎么用?Python Request.translations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.Request
的用法示例。
在下文中一共展示了Request.translations方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from werkzeug import Request [as 别名]
# 或者: from werkzeug.Request import translations [as 别名]
def __call__(self, environ, start_response):
request = Request(environ)
lang = request.values.get('_lang')
if lang is None:
lang = (request.accept_languages.best or 'en').split('-')[0].lower()
if not has_language(lang):
lang = 'en'
request.translations = load_core_translations(lang)
request.translations.language = lang
response = None
if request.path == '/':
view = request.values.get('_current', 'start')
if request.values.get('_startsetup'):
response = self.start_setup(request)
elif view in self.views:
handler = self.views[view]
if handler is not None and \
request.values.get('_next'):
ctx = handler(request)
if ctx is not None:
response = self.handle_view(request, view, ctx)
if response is None:
if request.values.get('_next'):
view = self.next[view]
elif request.values.get('_prev'):
view = self.prev[view]
response = self.handle_view(request, view)
if response is None:
response = redirect('')
return response(environ, start_response)