【发布时间】:2021-03-28 03:08:07
【问题描述】:
我有一个带有动态 url 的“拼图”路线,具体取决于可以正常工作的拼图编号:
@app.route("/puzzle/<puzzle_id>")
@login_required
def puzzle(puzzle_id):
some sqlalchemy queries
return render_template('puzzle.html', other variables)
我尝试使用尝试路由做同样的事情,但在 html 中使用 jquery javascript 进行重定向:
-(jquery function above here that worked fine without the redirect)-
}).done(function (response) {
var attempt_num = response['attempt'];
var urli = "{{ url_for('attempt', attempt_num=attempt_num) }}";
console.log(urli)
window.location.href = urli;
路线:
@app.route("/attempt/<attempt_num>")
@login_required
def attempt(attempt_num):
some sqlalchemy queries to fill variables
print("render attempt template with attempt = "+str(attempt.id),file=sys.stderr,flush=True)
return render_template('attempt.html', other variables)
我的打印语句产生:
使用尝试 = 80 渲染尝试模板
并且烧瓶服务器显示:
127.0.0.1 - - [27/Mar/2021 19:50:27] "←[37mGET /attempt/80?redir=True HTTP/1.1←[0m" 200 - 127.0.0.1 - - [27/Mar/2021 19:50:27]“←[33mGET /attempt/HTTP/1.1←[0m”404 -
它看起来工作正常并尝试转到 /attempt/80,但随后它尝试转到 /attempt/ 而不是未定义的路由并导致 404。
【问题讨论】:
标签: javascript python flask