Skip to main content

Support Jinja2 templates for Muffin Framework

Project description

Muffin-Jinja2 – Support Jinja2 templates for Muffin Framework

Tests Status PYPI Version


  • python >= 3.8


Muffin-Jinja2 should be installed using pip:

pip install muffin-jinja2


import muffin
import muffin_jinja2

# Create Muffin Application
app = muffin.Application('example')

# Initialize the plugin
# As alternative: jinja2 = Jinja2(app, **options)
jinja2 = muffin_jinja2.Plugin()
jinja2.setup(app, template_folders=['src/templates'])

# Use it inside your handlers
async def index(request):
    context = {'var': 42}
    return await jinja2.render('index.html', **context)


Format: Name – Description (default value)

auto_reload – Auto reload changed templates (False)

cache_size – Cache templates (50)

extensions – Enable Jinja2 Extensions (None)

loader – Template loader (FileSystemLoader)

encoding – Default encoding for file loader (utf-8)

template_folders – List of template folders ([‘templates’])

You are able to provide the options when you are initiliazing the plugin:

jinja2.init(app, template_folders=['src/templates'], auto_reload=True)

Or setup it inside Muffin.Application config using the jinja2_ prefix:



Muffin.Application configuration options are case insensetive


# Register custom context processor
# could be a function/coroutine
def custom_context():
    return { 'VAR': 'VALUE' }

# Register a function into global context
def sum(a, b):
    return a + b

# Register a function with a different name
def mod(a, b):
    return a // b

# Register a filter
def test(value, a, b=None):
    return a if value else b

# Register a filter with a different name
def boolean(value):
    return bool(value)

async def index(request):
    """ Check for user is admin. """
    local_context = {'key': 'value'}
    return await jinja2.render('index.html', **local_context)

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at


Development of Muffin-Jinja2 happens at:


  • klen (Kirill Klenov)


Licensed under a MIT license.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for muffin-jinja2, version 0.6.4
Filename, size File type Python version Upload date Hashes
Filename, size muffin_jinja2-0.6.4-py3-none-any.whl (5.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size muffin-jinja2-0.6.4.tar.gz (5.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page