1

So I am creating a simple bottle.py app. I want to create a function that renders template simply, like this:

from bottle import Bottle
app = Bottle()
def render_template(template, args=None):
    i = open("templates/" + template)
    return str(i.read()).format(args)

@app.route("/")
def page():
    return render_template("template.tpl", args=("Hello", "World"))

The HTML file:

<html>
<head>
</head>
<body>
{}, {}!
</body>
</html>

There may be some existing templates for bottle.py, but I want to use this instead. How can I get the values of the tuple into the str.format() parameters?

Tarek Ahmed
  • 168
  • 9

0 Answers0