Skip to Content
Flask Web开发:基于Python的Web应用开发实战(第2版)
book

Flask Web开发:基于Python的Web应用开发实战(第2版)

by Miguel Grinberg
August 2018
Intermediate to advanced
230 pages
6h 42m
Chinese
O'Reilly Media, Inc. Beijing
Content preview from Flask Web开发:基于Python的Web应用开发实战(第2版)
部署
185
这个命令调用的函数之前都已经定义好了,现在只不过是在一个命令中集中调用,以简化
部署应用的过程。
如果你从
GitHub
上克隆了这个应用的
Git
仓库,那么可以执行
git checkout
17a
检出应用的这个版本。
定义这些函数时考虑到了多次执行的情况,所以即使多次执行也不会产生问题。每次安装
或升级应用时只需运行 deploy 命令,无须担心运行的时机不当而导致的副作用。
17.2
 把生产环境中的错误写入日志
在调试模式中运行的应用发生错误时,
Werkzeug
的交互式调试器会出现。网页中会显示错
误的
栈跟踪
,而且可以查看源码,甚至还能使用
Flask
的网页版交互调试器在每个栈帧的
上下文中执行表达式。
调试器是开发过程中调试问题的优秀工具,但显然不能在生产环境中使用。生产环境中发
生的错误会被静默掉,取而代之的是向用户显示一个
500
错误页面。不过幸好错误的栈跟
踪不会完全丢失,因为
Flask
会将其写入
日志文件
在应用启动过程中,
Flask
会创建一个
Python
logging.Logger
类实例,并将其附属到应
用实例上,通过
app.logger
访问。在调试模式中,日志记录器把日志写入控制台;但在生
产模式中,默认情况下没有配置日志的处理程序,所以如果不添加处理程序,就不会保存
日志。示例
17-2
中的改动配置一个日志处理程序,把生产模式中出现的错误通过电子邮件
发送给
FLASKY_ADMIN
设置的管理员。
示例
17-2
 
config.py
:应用出错时发送电子邮件
class ProductionConfig(Config): ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python机器学习基础教程

Python机器学习基础教程

Andreas C. Müller, Sarah Guido
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano
程序设计导论:Python语言实践

程序设计导论:Python语言实践

罗伯特 塞奇威克, 凯文 韦恩, 罗伯特 唐德罗

Publisher Resources

ISBN: 9787115489456