为烧瓶 url_for 传递动态 url 参数

pass dymanic url parameter for flask url_for

我有以下 URL 到一种形式的映射:

<a href="/home/downloads/application_one">Download Application</a>
<a href="/home/downloads/application_two">Download Application</a>
<a href="/home/downloads/application_three">Download Application</a>
<a href="/home/downloads/application_four">Download Application</a>

<form method="POST" action="{{ url_for('home.downloads') }}">

如何将 application_one、application_two、application_three、application_four 动态传递给表单中的“url_for”。

下面是我的路线:

@download.route('/downloads/<application_name>', methods=['GET', 'POST'])
def downloads(application_name):

将其作为第二个参数传递给 url_for

{{ url_for('home.downloads', application_name = "YOUR DYNAMIC APP NAME") }}

编辑:

对于动态的,您只需传递变量。

{{ url_for('home.downloads', application_name = application) }}

并且当您呈现模板时,发送您的动态值。

     application = "DO WHATEVER AND ASSIGN THE VALUE HERE"
     return render_template("template.html", application = application )

参考:https://flask.palletsprojects.com/en/2.1.x/quickstart/#url-building