Skip to content

rivrproject/rivr-jinja

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rivr-jinja

An extension to rivr for using the Jinja template engine.

Installation

$ pip install rivr-jinja

Usage

from rivr_jinja import *

View

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'
        }

Middleware

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)

Response

JinjaResponse(request, template_names=['index.html'], context={'name': 'World'})

License

rivr-jinja is released under the BSD license. See LICENSE.

About

An extension to rivr for using the Jinja template engine..

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages