From a102054d2b12dfa153949c8808d2ef379a9d2e3d Mon Sep 17 00:00:00 2001 From: wangruidong <940853815@qq.com> Date: Mon, 1 Jun 2026 18:31:40 +0800 Subject: [PATCH] fix: add _get_placeholder_context function and update template rendering logic --- apps/notifications/api/notifications.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/notifications/api/notifications.py b/apps/notifications/api/notifications.py index 335e7a0e0..eef4f6438 100644 --- a/apps/notifications/api/notifications.py +++ b/apps/notifications/api/notifications.py @@ -26,6 +26,14 @@ __all__ = ( ) +def _get_placeholder_context(contexts): + return { + item['name']: '{{ ' + item['name'] + ' }}' + for item in contexts + if item.get('name') + } + + class BackendListView(APIView): permission_classes = [IsValidUser] @@ -164,9 +172,10 @@ class TemplateViewSet(JMSGenericViewSet): item['content'] = f.read() item['source'] = 'data' else: - ctx = {x.get('name'): x.get('default') for x in item['contexts']} + ctx = _get_placeholder_context(item['contexts']) try: rendered = render_to_string(meta['template_name'], ctx) + item['template_content'] = rendered item['content'] = rendered item['source'] = 'original' except Exception as e: