简体   繁体   English

Python Flask 不提供自定义 500 模板/返回 IIS

[英]Python Flask doesn't serve custom 500 template/return on IIS

I am using Flask and blueprints on IIS.我在 IIS 上使用 Flask 和蓝图。 My issue is that when the 500 error is triggered it loads the default IIS 500 template and not what I want.我的问题是,当触发 500 错误时,它会加载默认的 IIS 500 模板,而不是我想要的。

I've tried several things and this is where I am.我已经尝试了几件事,这就是我所在的地方。 I have the following code我有以下代码

from flask import render_template,Blueprint
errorbp = Blueprint("errorbp",__name__)

@errorbp.app_errorhandler(404)
def page_not_found(e):
    return "404", 404

@errorbp.app_errorhandler(500)
def internal_server_error(e):
    return "500", 500

If I visit a page that does not exist, I get "404" back as intended.如果我访问一个不存在的页面,我会按预期返回“404”。 If I create an error on purpose, I get the following如果我故意创建错误,我会得到以下信息

在此处输入图像描述

Any suggestions as to what to do?关于做什么的任何建议? I presume I may need to do something with IIS at this point but what?我想我现在可能需要对 IIS 做点什么,但是什么? I've edited/remove the 5xx status codes/page and still nothing我已经编辑/删除了 5xx 状态代码/页面,但仍然没有

What you need to do is, open the error pages module, double-click the 500 status code , set the path of your template in the file path , and IIS will send the content of the file as a custom error response.您需要做的是,打开error pages模块,双击500 status code ,在file path中设置您的模板路径,IIS 会将文件内容作为自定义错误响应发送。

In addition, IIS has two other ways to respond to an error: by executing an URL or by redirecting the request.此外,IIS 还有另外两种响应错误的方法:执行 URL 或重定向请求。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM