【发布时间】:2021-08-09 00:51:27
【问题描述】:
我有一个包含两个网址的索引页面:
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html')
当我转到https://localhost/ 时,它工作正常,但https://localhost/index 也是有效的。我希望 https://localhost/index 始终重定向到 https://localhost/ 而不必执行以下操作:
@app.route('/')
def index():
return render_template('index.html')
@app.route('/index')
def index_redirect():
return redirect(url_for('index'))
【问题讨论】:
-
我不明白。如果第一个示例有效(并且确实有效),那么问题是什么?
-
您能解释一下“重定向”是什么意思吗? HTTP 术语有一个特定的含义,返回 301 或 302 状态码并返回一个新的
location,但听起来这不是你想要的,那么,你想要什么?
标签: python flask url-routing