Skip to content

Commit 248fc5f

Browse files
committed
Use re.sub to replace template variables
1 parent e16611f commit 248fc5f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/Ui/UiRequest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,12 @@ def sendHeader(self, status=200, content_type="text/html", noscript=False, allow
294294
# Renders a template
295295
def render(self, template_path, *args, **kwargs):
296296
template = open(template_path, encoding="utf8").read()
297-
for key, val in list(kwargs.items()):
298-
template = template.replace("{%s}" % key, "%s" % val)
299-
return template.encode("utf8")
297+
def renderReplacer(m):
298+
return "%s" % kwargs.get(m.group(1), "")
299+
300+
template_rendered = re.sub("{(.*?)}", renderReplacer, template)
301+
302+
return template_rendered.encode("utf8")
300303

301304
# - Actions -
302305

0 commit comments

Comments
 (0)