diff --git a/python_web/flasky/errorpages.py b/python_web/flasky/errorpages.py index b273286..7acd742 100644 --- a/python_web/flasky/errorpages.py +++ b/python_web/flasky/errorpages.py @@ -1 +1,17 @@ -# 自定义错误页面 \ No newline at end of file +# 自定义错误页面 +# 404 客户端请求未知页面或路由 +# 500 应用有未处理的异常 + +from flask import Flask +from flask import render_template +app=Flask(__name__) + +@app.errorhandler(404) +def page_not_found(e): + return render_template('404.html'), 404 + +@app.errorhandler(500) +def internal_server_error(e): + return render_template('500.html'), 500 + +app.run(host='0.0.0.0', port=19722) \ No newline at end of file diff --git a/python_web/flasky/static.py b/python_web/flasky/static.py new file mode 100644 index 0000000..f5c5b30 --- /dev/null +++ b/python_web/flasky/static.py @@ -0,0 +1 @@ +# 静态文件 \ No newline at end of file diff --git a/python_web/flasky/templates/404.html b/python_web/flasky/templates/404.html new file mode 100644 index 0000000..ec865af --- /dev/null +++ b/python_web/flasky/templates/404.html @@ -0,0 +1 @@ +

Page Not Found

\ No newline at end of file diff --git a/python_web/flasky/templates/500.html b/python_web/flasky/templates/500.html new file mode 100644 index 0000000..20196b8 --- /dev/null +++ b/python_web/flasky/templates/500.html @@ -0,0 +1 @@ +

Internal Server Error ! Error

\ No newline at end of file