Search code examples
pythonframeworkstemplate-enginebottle

Bottle @view vs template()


Rendering a view using template():

@get('/start/<page:int>')
def start(page=1):
    return template('start', page=page)

Same example using a view() decorator:

@get('/start/<page:int>')
@view('start')
def start(page=1):
    return dict(page=page)

Is there any difference between the two other than personal preference?


Solution

  • Well, I am not a professional developer so I may say something that goes against most basic good manners in coding, but I find more useful to use return template() because I can use several templates, while with view decorator that is not possible. E.G:

    @get('/start/<page:int>')
    def start(page=1):
        return template('header',username=username)+template('start', page=page)+template('foot')
    

    Of course it is possible to do this with @views and %include subtemplates in the template, and probably in one million other ways too, but... it's a difference!

    ...Or is it possible to call several templates within one @view?