Created
April 5, 2014 04:50
-
-
Save rlander/9987644 to your computer and use it in GitHub Desktop.
model query from jinja macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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