1 ###设置debug模式
2 1、在app.run()中传入一个关键字阐述debug,app.run(debug=True),就设置当前项目为debug模式;
3 2、debug模式的两大功能:
4 *当程序出现问题的时候,可以在页面中看到错误信息和出错的位置
5 *只要修改了项目中的python文件,程序会自动加载,不需要手动重新启用服务器
6
7 ###使用配置文件:
8 1、新建一个‘config.py’文件,内容写DEBUG=True
9 2、在主app文件中导入这个文件,并且配置到‘app’中,示例代码如下:
10 '''
11 import config
12 app.config.from_object(config)
13 '''
14 3、还有许多其他参数,都是放在这个config.py’文件中,比如’SECRET_KEY'和'SQLALCHEMY'
15 开启debug模式方法1:
16 from flask import Flask
17
18 app = Flask(__name__)
19
20 @app.route('/')
21 def hello_world():
22 a = 1
23 b = 0
24 c = a / b
25 return '你好'
26
27 if __name__ == '__main__':
28 app.run(debug=True)#开启debug模式
开启debug模式方法2
1 from flask import Flask
2 import config
3
4 app = Flask(__name__)
5 app.config.from_object(config)
6
7 @app.route('/')
8 def hello_world():
9 a = 1
10 b = 0
11 c = a / b
12 return '你好'
13
14 if __name__ == '__main__':
15 app.run()