Using SimpleTemplate in Bottles

I am new to frameworks like Bottle and working on documentation / tutorial. Now I have a problem with the engine template:

I have a file called index.tplin my folder views. (this is plain html)
When I use the following code, it works to display my html:

from bottle import Bottle, SimpleTemplate, run, template

app = Bottle()

@app.get('/')
def index():
    return template('index')

run(app, debug=True)

Now I want to implement this engine in my project and do not want to use template()
I want to use it in the documentation, for example:

tpl = SimpleTemplate('index')

@app.get('/')
def index():
    return tpl.render()

But if I do, the browser will only show me a white page with the word

Index

instead of loading the template.
The documentation no longer contains information on how I use this OO approach. I just could not understand why this is happening and how I should do it right ...

+4
2

, :

tpl = SimpleTemplate(name='views/index.tpl')  # note the change here

@app.get('/')
def index():
    return tpl.render()
+4

SimpleTemplate:

>>> from bottle import SimpleTemplate
>>> tpl = SimpleTemplate('Hello {{name}}!')
>>> tpl.render(name='World')
u'Hello World!'
-2

All Articles