Flask入门教程FLASK_APP ; FLASK_ENV 用来设置程序运行的环境,默认为 production 。 在开发时,我们需要开启调试模式(debug mode)。调试模式可以通过将系统环 境变量 FLASK_ENV 设为 development 来开启。调试模式开启后,当程序出 错,浏览器页面上会显示错误信息;代码出现变动后,程序会自动重载。 为了不用每次打开新的终端会话都要设置环境变量,我们安装用来管理系统环境变 env 在新创建的 .flaskenv 文件里,我们写入一行 FLASK_ENV=development ,将环境 变量 FLASK_ENV 的值设为 development ,以便开启调试模式: FLASK_ENV=development 实验时间 在这个小节,我们可以通过做一些实验,来扩展和加深对本节内容的理解。 修改视图函数返回值 首先,你可以自由修改视图函数的返回值,比如: 打开文件管理器,你会发现项目根目录下出现了新创建的数据库文件 data.db。这 个文件不需要提交到 Git 仓库,我们在 .gitignore 文件最后添加一行新规则: *.db 如果你改动了模型类,想重新生成表模式,那么需要先使用 db.drop_all() 删 除表,然后重新创建: >>> db.drop_all() >>> db.create_all() 注意这会一并删除所有数据,如果你想在不破坏数据库内的数据的前提下变更表的0 码力 | 127 页 | 7.62 MB | 1 年前3
 Flask Documentation (1.1.x)PIN: 223-456-919 Watch Extra Files with the Reloader When using development mode, the reloader will trigger whenever your Python code or imported modules change. The reloader can watch additional files io/en/latest/], which we will use for this guide. Make sure to have it installed to follow along. Watch Out Please make sure in advance that any app.run() calls you might have in your application file apache.org/] webserver, consider using mod_wsgi [https://github.com/GrahamDumpleton/mod_wsgi]. Watch Out Please make sure in advance that any app.run() calls you might have in your application file0 码力 | 428 页 | 895.98 KB | 1 年前3
 Flask Documentation (1.1.x)PIN: 223-456-919 Watch Extra Files with the Reloader When using development mode, the reloader will trigger whenever your Python code or imported modules change. The reloader can watch additional files server is uwsgi, which we will use for this guide. Make sure to have it installed to follow along. Watch Out Please make sure in advance that any app.run() calls you might have in your application file consider using mod_wsgi. 1.22. Deployment Options 159 Flask Documentation (1.1.x), Release 1.1.4 Watch Out Please make sure in advance that any app.run() calls you might have in your application file0 码力 | 291 页 | 1.25 MB | 1 年前3
共 3 条
- 1
 













