search

Home  >  Q&A  >  body text

python - page_not_found(e)中e代表的是什么?

《Flask web development》 3.3自定义错误页面

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404
    

使用errorhandler装饰器,其中page_not_found(e)是继承与e的子类么?这个e代表的是什么意思?

怪我咯怪我咯2802 days ago1618

reply all(4)I'll reply

  • 阿神

    阿神2017-04-18 09:44:05

    From the definition, e is the parameter of page_not_found, and e may be an instance of Exception, which can be identified by
    type(e).

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:44:05

    You will know if you try without writing e. The foundation is not solid. . .

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:44:05

    I saw this place too. See it from this Chinese document

    An error handler is a function similar to a view function, but it is executed when an error occurs, and the error is passed in as a parameter. Generally the error will be an HTTPException , but in some cases it will be other errors: the internal server's error handler will be executed with the actual code error being caught as a parameter.

    This little e can be an error caused by HTTP or other errors (thank you for the reminder).

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:44:05

    e is an error object. The error information is stored in this variable, similar to:

    try:
        eat()
    except Exception as e:
        print(e)

    reply
    0
  • Cancelreply