擅长:python、mysql、java
<p>从<a href="http://jinja.pocoo.org/docs/dev/templates/#filters">Jijna docs</a>开始</p>
<blockquote>
<p>Variables can be modified by filters. Filters are separated from the variable by a pipe symbol (|) and may have optional arguments in parentheses. Multiple filters can be chained. The output of one filter is applied to the next.</p>
</blockquote>
<p>过滤器设计为一次修改一个变量。您正在寻找<a href="http://flask.pocoo.org/docs/0.10/templating/#context-processors">^{<cd1>}</a>:</p>
<blockquote>
<p>Variables are not limited to values; a context processor can also make functions available to templates (since Python allows passing around functions)</p>
</blockquote>
<p>例如</p>
<pre><code>@app.context_processor
def add():
def _add(int1, int2):
return int(int1) + int(int2)
return dict(add=_add)
</code></pre>
<p>可以在模板中用作</p>
^{pr2}$
<p>您可以将此作为您的<code>posts_page</code>方法:</p>
<pre><code>@app.context_processor
def posts_page():
def _posts_page(post_id, company_id):
# ...
return value
return dict(posts_page=_posts_page)
</code></pre>