完成作业后将Flask重定向到上一个url

完成作业后将Flask重定向到上一个url,flask,Flask,烧瓶 模板 <a href="{{url_for('delete',file_path=file_path)}}"> <img src="/static/icons/backspace-fill.svg" alt="" width="12" height="12" title="Delete"> </a> app.py @app.rou

烧瓶

模板

<a href="{{url_for('delete',file_path=file_path)}}">
<img src="/static/icons/backspace-fill.svg" alt="" width="12" height="12" title="Delete">
</a>

app.py

@app.route("/delete/<path:file_path>", methods=['GET', 'POST'])
def delete(file_path):
    os.remove(os.path.join(root_path, file_path))
    return redirect(request.url)
@app.route(“/delete/”,方法=['GET','POST'])
def delete(文件路径):
移除(os.path.join(根路径、文件路径))
返回重定向(request.url)
在定向到“/delete/…”后,我想返回我以前的url(不是delete…)
如何以最少的实现来实现这一点?

您需要在删除中传递要重定向到的url

<a href="{{url_for('delete',file_path=file_path, redirect_url='...your_redirect_url_here...')}}">
    <img src="/static/icons/backspace-fill.svg" alt="" width="12" height="12" title="Delete">
</a>

然后你可以在你的路线中抓住它并相应地重定向

@app.route("/delete/<path:file_path>", methods=['GET', 'POST'])
def delete(file_path):
    os.remove(os.path.join(root_path, file_path))
    return redirect(request.values['redirect_url'])
@app.route(“/delete/”,方法=['GET','POST'])
def delete(文件路径):
移除(os.path.join(根路径、文件路径))
返回重定向(request.values['redirect\u url'])

这通常在登录表单中完成,成功登录后,用户将被重定向到他们试图访问的原始url。您可以通过谷歌“Flask登录下一个参数”了解更多信息。

Super谢谢!在烧瓶现场没有发现这个