fix: add _get_placeholder_context function and update template rendering logic

This commit is contained in:
wangruidong
2026-06-01 18:31:40 +08:00
committed by 老广
parent 135289f651
commit a102054d2b

View File

@@ -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: