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.7


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)


Name Default value Description
auto_reload False Auto reload changed templates
cache_size 50 Cache templates
extensions None Enable Jinja2 Extensions (None | list)
loader FileSystemLoader Template loader
encoding utf-8 Default encoding for file loader
template_folders ['templates'] List of template folders

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 for example:



Muffin.Application configuration options are case insensitive


# 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 1.4.0
Filename, size File type Python version Upload date Hashes
Filename, size muffin_jinja2-1.4.0-py3-none-any.whl (5.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size muffin-jinja2-1.4.0.tar.gz (5.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page