gpt4 book ai didi

python - 如何重定向到外部 404 页面 python flask

转载 作者:太空狗 更新时间:2023-10-29 22:06:40 25 4
gpt4 key购买 nike

我正在尝试将我的 404 重定向到这样的外部 URL:

@app.route('404')
def http_error_handler(error):
return flask.redirect("http://www.exemple.com/404"), 404

但它不起作用。我不断得到:

Not FoundThe requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

最佳答案

你应该尝试这样的事情:

from flask import render_template

@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404

来源http://flask.pocoo.org/docs/1.0/patterns/errorpages/

关于python - 如何重定向到外部 404 页面 python flask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29516093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com