The simplest and not secure way is to use str.format:
>>> import time
>>> currentTime = time.ctime()
>>>
>>> currentTime
'Fri Jul 1 06:50:37 2016'
>>> s = '''
<div>
<b> Time is {}</b>
</div>'''.format(currentTime)
>>>
>>> s
'\n<div>\n<b> Time is Fri Jul 1 06:50:37 2016</b>\n</div>'
But that's not the way I suggest to you, what I strongly recommend to you is to use jinja2 template rendering engine.
Here is a simple code to work with it:
>>> import jinja2
>>> import os
>>>
>>> template_dir = os.path.join(os.path.dirname(__file__), 'templates')
>>> jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
autoescape=True)
>>> def render_str(self, template, **params):
t = jinja_env.get_template(template)
return t.render(params)
So here you need to create a folder on your working directory called templates, which will have your template, for example called CurrentTime.html:
<div>
<b> Time is {{ currentTime }}</b>
Then simply:
>>> import time
>>> currentTime = time.ctime()
>>>
>>> render_str('CurrentTime.html', currentTime=currentTime)