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