An extension to rivr for using the Jinja template engine.
$ pip install rivr-jinja
from rivr_jinja import *
Example, registering the template about.html
with the /about
endpoint in
our router:
@router.register(r'about')
JinjaView.as_view(template_name='about.html')
Sub-classing JinjaView
:
class View(JinjaView):
template_name = 'about.html'
class View(JinjaView):
template_name = 'about.html'
def get_context_data(self, **kwargs):
return {
'template': 'variable'
}
To attach a Jinja environment to any JinjaResponse
, use the JinjaMiddleware
.
from jinja2 import Environment, DictLoader
loader = DictLoader({'index.html': 'Hello {{ name }}'})
environment = Environment(loader=loader)
middleware = JinjaMiddleware(environment)
JinjaResponse(request, template_names=['index.html'], context={'name': 'World'})
rivr-jinja is released under the BSD license. See LICENSE.