diff --git a/py4web/core.py b/py4web/core.py index da825f29..368b0dfd 100644 --- a/py4web/core.py +++ b/py4web/core.py @@ -514,10 +514,7 @@ def on_success(self, context): output = context["output"] flash = self.local.flash or "" if isinstance(output, dict): - if "template_inject" in context: - context["template_inject"]["flash"] = flash - else: - context["template_inject"] = dict(flash=flash) + context["template_inject"]["flash"] = flash elif self.local.flash is not None: response.headers.setdefault("component-flash", json.dumps(flash)) @@ -611,7 +608,7 @@ def on_success(self, context): ctx = dict(request=request) ctx.update(HELPERS) ctx.update(URL=URL) - ctx.update(context.get("template_inject", {})) + ctx.update(context["template_inject"]) ctx.update(output) ctx["__vars__"] = output app_folder = os.path.join(os.environ["PY4WEB_APPS_FOLDER"], request.app_name) @@ -993,6 +990,7 @@ def wrapper(*args, **kwargs): "output": None, "exception": None, "processed": processed, + "template_inject": {}, } try: for fixture in fixtures: diff --git a/py4web/utils/auth.py b/py4web/utils/auth.py index e8b501eb..a32e2f95 100644 --- a/py4web/utils/auth.py +++ b/py4web/utils/auth.py @@ -339,7 +339,7 @@ def deny_action(self, action_name): def on_success(self, context): if self.inject: - context["template_inject"] = {"user": self.get_user()} + context["template_inject"]["user"] = self.get_user() def define_tables(self): """Defines the auth_user table"""