如何重定向到外部404页面的python烧瓶
问题描述:
如何实现这一点我是新来的python和烧瓶,我试图将我的404重定向到一个外部url像这样:
How can I achieve this I'm new to python and flask, I am trying to redirect my 404 to a external url like this:
@app.route('404')
def http_error_handler(error):
return flask.redirect("http://www.exemple.com/404"), 404
但它不工作我得到
未找到
请求的URL在服务器上找不到。如果您手动输入了URL,请检查您的拼写,然后重试。
答
您应该尝试这样:
from flask import render_template
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404