Catching a 500 server error in Flask

后端 未结 6 1241
-上瘾入骨i
-上瘾入骨i 2021-02-01 12:41

I love Flask\'s error catching. It\'s beautifully simple:

@app.errorhandler(404)
def pageNotFound(error):
    return \"page not found\"

works

6条回答
  •  隐瞒了意图╮
    2021-02-01 13:33

    What you have described is, by default, how Flask works. My assumption is that you are running in debug mode, and therefore exceptions are being shown to you in the debug screen. Make sure debug mode is off, then try again. Here is a comment directly from the code itself:

    Default exception handling that kicks in when an exception occurs that is not caught. In debug mode the exception will be re-raised immediately, otherwise it is logged and the handler for a 500 internal server error is used. If no such handler exists, a default 500 internal server error message is displayed.

提交回复
热议问题