擅长:python、mysql、java
<p>另外,对于那些使用由变量构造的catch all路由的用户:如果<code>url_for</code>被传递了包含变量的字典,那么Flask将正确地创建url路径。</p>
<p>例如。。。</p>
<p>应用程序py:</p>
<pre><code>app.route('/<path:pattern1>')
app.route('/<path:pattern1>/<path:pattern2>')
def catch_all(pattern1, pattern2=None):
return render_template('template.html', p1=pattern1, p2=pattern2)
app.route('/test')
def test_routing:
args = {'pattern1': 'Posts', 'pattern2': 'create'}
return render_template('test.html', args=args)
</code></pre>
<p>测试.html:</p>
<pre><code><a href="{{url_for('catch_all', **args)}}">click here</a>
</code></pre>
<p>单击“单击此处”链接时,您将被定向到“发布/创建”路径。</p>