Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SimpleTemplate in Bottle

I'm new in Frameworks like Bottle and working through the Documentation/Tutorial. Now I got a Problem with the Template-Engine:

I have a file called index.tpl in my folder views. (it's 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 dont want to use template()
I want to use it as it stands in the documentation, like:

tpl = SimpleTemplate('index')

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

But if I do so, the Browser shows me just a white page with the word

index

written, instead of loading the template.
In the documentation, there is no further information on how I use this OO approach. I just couldn't figure out why this happens and how I have to do it right...

like image 234
uloco Avatar asked Nov 22 '13 13:11

uloco


1 Answers

Here's a nice, simple solution in the spirit of your original question:

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

@app.get('/')
def index():
    return tpl.render()
like image 97
ron rothman Avatar answered Oct 11 '22 16:10

ron rothman