我基本上需要的是以下内容:
{{ url_for(current_view) }}
Run Code Online (Sandbox Code Playgroud)
在Jinja2模板中,如果响应来自:
@app.route('/')
def index():
return render('index.html')
Run Code Online (Sandbox Code Playgroud)
然后current_view等于"index",即实际的视图名称,这样就url_for可以了.
为了提供一些上下文,使用时实际上出现了这个问题flask-babel.我希望有一个"切换语言按钮",基本上重定向到相同的URL,但使用不同的语言代码,如:
{{ url_for(current_view, lang_code="es") }}
Run Code Online (Sandbox Code Playgroud)
如果你在英文页面,lang_code="en"如果你在西班牙语页面.
Ret*_*old 13
你可以使用request.endpoint:
{{ url_for(request.endpoint) }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1376 次 |
| 最近记录: |