from flask import Flask
from flask import abort

app = Flask(__name__)

@app.route('/')
def index():
return 'index'

@app.route('/demo1')
def demo1():
# 主动抛出HTTP指定错误状态码
# abort(404)
a = 0
b = 1 / a
return 'demo1'

# 使用装饰器的形式去捕获指定的错误码和异常
@app.errorhandler(404)
def page_not_found(error):
return "咦~页面不见了~"

@app.errorhandler(ZeroDivisionError)
def zero_division_error(error):
return '除数不能为0'

if __name__ == '__main__':
app.run(debug=True)

flask error的更多相关文章

  1. 让flask在出现语法错误时仍然自动重启

    1问题描述: flask自带的reload只能在语法没毛病的情况下auto_relaod,但是如果有语法错误,进程就会报错退出. 这时修改完语法错误,还得在控制台按“↑”和“enter”重新执行一次p ...

  2. flask为blueprint增加error_handler

    对整个app增加errorhandler,只需如下: @portal_page.errorhandler(404) def page_not_found(error): cats = Category ...

  3. 使用国内镜像通过pip安装python的一些包 Cannot fetch index base URL http://pypi.python.org/simple/

    原文地址:http://www.xuebuyuan.com/1157602.html 学习flask,安装virtualenv环境,这些带都ok,但是一安装包总是出错无法安装, 比如这样超时的问题: ...

  4. Flask的socket.error:10053

    一脸懵逼: 学习python一段时间,最近使用flask搭建了一个服务器,然后使用phantom(相当于浏览器)发送请求发送了几条flask就挂掉了,报错信息如下: 由于个人python经验不是很足, ...

  5. Flask and uWSGI - unable to load app 0 (mountpoint='') (callable not found or import error)

    Here is my directory structure: -/path/to/folder/run.py -|app -|__init__.py -|views.py -|templates - ...

  6. Error generating Swagger server (Python Flask) from Swagger editor

    1down votefavorite   http://stackoverflow.com/questions/36416679/error-generating-swagger-server-pyt ...

  7. flask开发遇到Internal Server Error的解决办法

    flask开发过程中遇到了Internal Server Error错误,可以在代码加上debug app.debug=True 这样就能看到错误信息了

  8. flask学习之解决Internal Server Error问题的方式之一

    最近在学习flask web development的时候,遇到了这么一个问题,就是照着书上敲的代码,跑起来是Internal server error,由于中途学的时候为了方便,改用pycharm来 ...

  9. Airflow安装异常:ERROR: flask-appbuilder 1.12.3 has requirement Flask<2,>=0.12, but you'll have flask 0.11.1 which is incompatible.

    1 详细异常: ERROR: flask-appbuilder 1.12.3 has requirement Flask<2,>=0.12, but you'll have flask 0 ...

随机推荐

  1. 5.基于优化的攻击——CW

    CW攻击原论文地址——https://arxiv.org/pdf/1608.04644.pdf 1.CW攻击的原理 CW攻击是一种基于优化的攻击,攻击的名称是两个作者的首字母.首先还是贴出攻击算法的公 ...

  2. Failed global initialization:FileNotOpen: Failed to open "C:\MongoDB\data\log\mongo.log" 安装MongoDB时卡死

    在安装MongoDB的时候,下载了3.6版本,安装过程中发现到一半就卡死了,后面换了一个较低版本的才安装成功 这里是所有MongoDB版本的下载地址: https://www.mongodb.org/ ...

  3. import文件时 ~/ 不识别问题(react)

    在最近写的react的项目中,在webpack中配置的“~”可以定位到根路径,但是知道在同事在windows中跑程序时,发现怎么都不识别这个路径,所有相关文件都could not find modul ...

  4. SpringCloud教程 | 第二篇: 服务消费者(rest+ribbon)

    在上一篇文章,讲了服务的注册和发现.在微服务架构中,业务都会被拆分成一个独立的服务,服务与服务的通讯是基于http restful的.Spring cloud有两种服务调用方式,一种是ribbon+r ...

  5. CSS(八)

    CSS3 transform变换 1.translate(x,y) 设置盒子位移2.scale(x,y) 设置盒子缩放3.rotate(deg) 设置盒子旋转4.skew(x-angle,y-angl ...

  6. 最大子矩阵和问题dp

    给定一个矩阵 matrix,其中矩阵中的元素可以包含正数.负数.和0,返回子矩阵的最大累加和.例如,矩阵 matrix 为: 0 -2 -7 0 9 2 -6 2 -4 1 -4 1 -1 8 0 - ...

  7. [LeetCode] Reaching Points 到达指定点

    A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). Given a ...

  8. I Think I Need a Houseboat POJ - 1005

    I Think I Need a Houseboat POJ - 1005 解题思路:水题 #include <iostream> #include <cstdio> #inc ...

  9. tp 5.0 mysql 事物

    mysql  默认 MyISAM存储引擎,不支持事物处理,InnoDB存储引擎提供了具有提交.回滚和崩溃恢复能力的事务安全.但是对比Myisam的存储引擎,InnoDB写的处理效率差一些并且会占用更多 ...

  10. dtIntersectSegmentPoly2D 2D上的线段与多边形相交计算 产生结果:是否相交,线段跨越的开始和结束百分比,相交的边

    dtIntersectSegmentPoly2D(startPos, endPos, verts, nv, tmin, tmax, segMin, segMax): http://geomalgori ...