Question

I just built my first Bottle.py app on GAE. It's working except that when I change the templates I have to restart the dev server to see the changes. The docs say that template caching is supposed to be disabled when bottle.debug(True), and that you can call bottle.TEMPLTE.clear() as well, but neither of those work. I also tried setting run(reloader=True) but that causes an error. What am I doing wrong? Does bottle.debug() work for anyone else on GAE?

import bottle
bottle.debug(True)
bottle.TEMPLATES.clear()

@bottle.route('/')
def index(name='World'):
    return bottle.template('main')

bottle.run(server='gae')

Update: Instead of using bottle.run(server='gae'), I included the standard main() function myself and now it works.

def main():
  app = bottle.default_app()
  util.run_wsgi_app(app)

if __name__ == "__main__":
  main()
Was it helpful?

Solution

The standard method introduced by Bottle/GAE doc is:

app = bottle.app()

then invoke dev_appserver.py, it reads app.yaml and import your app from the script you defined, and handle everything else for a GAE environment.

You shouldn't run your .py directly. Running from the bottle way will skip those handles from dev_appserver, including the template cached mechanism. Of course, using the util from Google does trick way and works, but according to uwsgi or other wsgi related projects' documents, the app variable in the script module is the object should be offered for the upper handling.

OTHER TIPS

From the documentation:

Templates are cached in memory after compilation. Modifications made to the template files will have no affect until you clear the template cache. Call bottle.TEMPLATES.clear() to do so. Caching is disabled in debug mode.

The method run:

bottle.run( debug = True )

will enable debuggmode.

The default template is SimpleTemplate in stable version 0.11.6.

You can write your own adapter for your favourite template engine or use one of the predefined adapters. Currently there are four fully supported template engines:

Class,URL,Decorator,Render,function

SimpleTemplate, SimpleTemplate, Engine, view(), template()

MakoTemplate, http://www.makotemplates.org, mako_view(), mako_template()

CheetahTemplate, http://www.cheetahtemplate.org/, cheetah_view(), cheetah_template()

Jinja2Template, http://jinja.pocoo.org/, jinja2_view(), jinja2_template()

>>> Try using some other template engine, than the default. <<<

To use MakoTemplate as your default template engine, just import its specialised decorator and render function:

from bottle import mako_view as view, mako_template as template

>>> Check that you dont have duplicated files in the view paths <<<

TEMPLATE_PATH = ['./', './views/']

>>> Print out templates dictionary <<<

print bottle.TEMPLATES
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top