Skip to content

Instantly share code, notes, and snippets.

@rlander
Created April 5, 2014 04:50
Show Gist options
  • Save rlander/9987644 to your computer and use it in GitHub Desktop.
Save rlander/9987644 to your computer and use it in GitHub Desktop.
model query from jinja macros
env.globals['m'] = sys.modules['application.models']
Assuming your application is already fully imported if you render a
template, your macro can do something like this::
{% macro recent_news(num) %}
{% set news = m.NewsModel.select(...).limit(num) %}
...
{% endmacro %}
And then like you did with mako::
{% import 'news/widget.html' as news %}
${news.recent_news(5)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment