Catching a 500 server error in Flask

后端 未结 6 1282
-上瘾入骨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:37

    here is my code snippt

    @app.route('/')
    def index():
        raise Exception("Can't connect to database")
    
    
    @app.errorhandler(Exception)
    def exception_handler(error):
        return "!!!!"  + repr(error)
    

提交回复
热议问题