Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Jinja2 templates for Muffin framework

License

NotificationsYou must be signed in to change notification settings

klen/muffin-jinja2

Repository files navigation

Muffin-Jinja2 -- Support Jinja2 templates forMuffin Framework

Tests StatusPYPI Version
  • python >= 3.9

Muffin-Jinja2 should be installed using pip:

pip install muffin-jinja2
importmuffinimportmuffin_jinja2# Create Muffin Applicationapp=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@app.route('/')asyncdefindex(request):context= {'var':42}returnawaitjinja2.render('index.html',**context)
NameDefault valueDescription
auto_reloadFalseAuto reload changed templates
cache_size50Cache templates
extensionsNoneEnable Jinja2 Extensions (None | list)
loaderFileSystemLoaderTemplate loader
encodingutf-8Default 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 insideMuffin.Application config using the jinja2_ prefix for example:

JINJA2_AUTO_RELOAD=TrueJINJA2_TEMPLATE_FOLDERS= ['tmpls']

Muffin.Application configuration options are case insensitive

# Register custom context processor# could be a function/coroutine@jinja2.add_contextdefcustom_context():return {'VAR':'VALUE' }# Register a function into global context@jinja2.add_globaldefsum(a,b):returna+b# Register a function with a different name@jinja2.add_global('div')defmod(a,b):returna//b# Register a filter@jinja2.add_filterdeftest(value,a,b=None):returnaifvalueelseb# Register a filter with a different name@jinja2.add_filter('bool')defboolean(value):returnbool(value)@app.route('/')asyncdefindex(request):""" Check for user is admin. """local_context= {'key':'value'}returnawaitjinja2.render('index.html',**local_context)

If you have any suggestions, bug reports orannoyances please report them to the issue trackerathttps://github.com/klen/muffin-jinja2/issues

Development of Muffin-Jinja2 happens at:https://github.com/klen/muffin-jinja2

  • klen (Kirill Klenov)

Licensed under aMIT license.

About

Jinja2 templates for Muffin framework

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp