Use re.sub to replace template variables
This commit is contained in:
parent
e16611f15a
commit
248fc5f015
1 changed files with 6 additions and 3 deletions
|
@ -294,9 +294,12 @@ class UiRequest(object):
|
|||
# Renders a template
|
||||
def render(self, template_path, *args, **kwargs):
|
||||
template = open(template_path, encoding="utf8").read()
|
||||
for key, val in list(kwargs.items()):
|
||||
template = template.replace("{%s}" % key, "%s" % val)
|
||||
return template.encode("utf8")
|
||||
def renderReplacer(m):
|
||||
return "%s" % kwargs.get(m.group(1), "")
|
||||
|
||||
template_rendered = re.sub("{(.*?)}", renderReplacer, template)
|
||||
|
||||
return template_rendered.encode("utf8")
|
||||
|
||||
# - Actions -
|
||||
|
||||
|
|
Loading…
Reference in a new issue