search

Home  >  Q&A  >  body text

python - How to get more information after overriding the method of flask's errorhandler (BaseError)

The reference article is this
http://www.qingpingshan.com/b...

Those errors that directly rewrite 404,500 are no problem
But if you want to use your own defined errors, it is not possible, and errors cannot trigger this errorhandler(BaseError)Customized errors

曾经蜡笔没有小新曾经蜡笔没有小新2755 days ago565

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-18 11:04:04

    I didn’t see your BaseError very specifically

    But the best practice is generally like this:

    Define an exception

    # exceptions.py
    
    class MyException(Exception):
        pass
    
    # error_handlers.py
    
    @app.errorhandler(MyException):
    def handler_myexception(error):
        pass
    

    are all defined, remember to import it in the appropriate place (for example, import it inside __init.py__) to let flask know that you have defined this Exception processing class.

    reply
    0
  • Cancelreply