Created
February 11, 2012 21:54
-
-
Save defnull/1804479 to your computer and use it in GitHub Desktop.
Bottle templates example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
really awesome! The more I learn about bottle, the more I like it
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
This is an API preview for app-specific template configuration. What dou you think? Easy enough?