def __call__(self, f):
"""
Applies area initialization logic to a request handling function, for example by loading user session.
:param f: the request handler to be decorated.
:return: a wrapped request handler that loads user information.
"""
@wraps(f)
async def wrapped(request):
# set the area property inside the request object
request.area = self.name
try:
await self.before_request(request)
except InvalidCultureException:
# redirect to a proper url
return HTTPFound(self.get_fallback_url(request))
except InvalidAntiforgeryTokenException:
raise HTTPForbidden()
return await f(request)
return wrapped
评论列表
文章目录