def update_context(self, context, app=None):
"""Replace the component's context with a new one.
Args:
context (dict): The new context to set this component's context to.
Keyword Args:
app (flask.Flask, optional): The app to update this context for. If
not provided, the result of ``Component.app`` will be used.
"""
if (app is None and self._context is _CONTEXT_MISSING
and not in_app_context()):
raise RuntimeError("Attempted to update component context without"
" a bound app context or eager app set! Please"
" pass the related app you want to update the"
" context for!")
if self._context is not _CONTEXT_MISSING:
self._context = ImmutableDict(context)
else:
key = self._get_context_name(app=app)
setattr(_CONTEXT_LOCALS, key, ImmutableDict(context))
评论列表
文章目录