Skip to content

Instantly share code, notes, and snippets.

@defnull
Created February 11, 2012 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save defnull/1804479 to your computer and use it in GitHub Desktop.
Save defnull/1804479 to your computer and use it in GitHub Desktop.
Bottle templates example
import bottle
app = bottle.Bottle()
# Template configuration
app.views.adapter = Jinja2Adapter
app.views.options['extensions'] = ['jinja2.ext.i18n']
app.views.globals['some_variable'] = 'some_value'
app.views.add_path('templates/', root=__file__)
# Shortcut to render templates directly.
render = app.views.render
@app.route('/', view='home')
def home():
return {}
@defnull
Copy link
Author

defnull commented Feb 11, 2012

This is an API preview for app-specific template configuration. What dou you think? Easy enough?

@andersoncardoso
Copy link

really awesome! The more I learn about bottle, the more I like it

@dwn-zz
Copy link

dwn-zz commented Apr 25, 2014

Does substituting views with template work? How about install_gettext_translations?

Alternative approach:
To use jinja2 with i18n can I simply substitute bottle.template() with bottle.jinja2_template().

Do you need to overide the prepare method in class Jinja2Template to add the env.install_gettext_translations(translations)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment