<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flask &#8211; 李辉 / Grey Li</title>
	<atom:link href="https://greyli.com/tag/flask/feed/" rel="self" type="application/rss+xml" />
	<link>https://greyli.com</link>
	<description>一个编程和写作爱好者的在线记事本</description>
	<lastBuildDate>Sat, 03 Jan 2026 12:59:26 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.26</generator>

<image>
	<url>https://greyli.com/wp-content/uploads/2025/03/avatar-500-compressed-144x144.jpg</url>
	<title>Flask &#8211; 李辉 / Grey Li</title>
	<link>https://greyli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>《Flask 从入门到进阶》正式发售</title>
		<link>https://greyli.com/new-flask-book/</link>
		<comments>https://greyli.com/new-flask-book/#comments</comments>
		<pubDate>Sun, 23 Nov 2025 14:25:36 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[读书与写作]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Flask Web开发实战]]></category>
		<category><![CDATA[Flask 从入门到进阶]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web 开发]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=5830</guid>
		<description><![CDATA[经过五年的写（拖）作（延），我的新书《Flask 从入门到进阶》终于出版了！作为《Flask Web 开发实战 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>经过五年的写（拖）作（延），我的新书《<a href="https://helloflask.com/book/4/">Flask 从入门到进阶</a>》终于出版了！作为《<a href="https://helloflask.com/book/1/">Flask Web 开发实战</a>》的全新升级版，新版本在原书的基础上进行了大量更新和调整，以便适应当下的技术栈。目前已经有现货可以购买：</p>
<ul>
<li><a href="https://item.jd.com/10197448824391.html">京东</a></li>
<li><a href="https://product.dangdang.com/12441003237.html">当当</a></li>
<li><a href="https://helloflask.com/book/4/signed/">作者签名版</a></li>
</ul>
<p>至此我在 Flask 这条人生支线的探索也算圆满了。我从大二自学 Python 和 Flask，毕业前开始写作《Flask Web 开发实战》，这本书出版的同时也成为了 Flask 的维护者，并且为大量相关项目贡献代码。从</span> 2018 年出版到现在，一共重印了 14 次，累计售出 2 万本（包括电子书）。收获了很多好评，在<a href="https://book.douban.com/subject/30310340/">豆瓣</a>上评分也保持在 9 分左右：</p>
<p><a href="https://greyli.com/wp-content/uploads/2025/11/flask-book-douban-page.png"><img class="aligncenter size-large wp-image-5834" src="https://greyli.com/wp-content/uploads/2025/11/flask-book-douban-page-1024x392.png" alt="" width="625" height="239" srcset="https://greyli.com/wp-content/uploads/2025/11/flask-book-douban-page-1024x392.png 1024w, https://greyli.com/wp-content/uploads/2025/11/flask-book-douban-page-150x57.png 150w, https://greyli.com/wp-content/uploads/2025/11/flask-book-douban-page-300x115.png 300w, https://greyli.com/wp-content/uploads/2025/11/flask-book-douban-page-624x239.png 624w, https://greyli.com/wp-content/uploads/2025/11/flask-book-douban-page.png 1364w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<p>到现在终于完成了新版本，而且还拿到了 Armin Ronacher（Flask 作者）的推荐语：</p>
<blockquote>
<p>Great resources make great developers, and it’s wonderful to see Flask supported by such high-quality education materials.</p>
</blockquote>
<p>感谢一直关注这本书并持续催更的朋友！这本书的完成是我们共同努力的结果 :D</p>
<p><a href="https://greyli.com/wp-content/uploads/2025/11/new-flaskbook.jpg"><img class="aligncenter wp-image-5843 " src="https://greyli.com/wp-content/uploads/2025/11/new-flaskbook-768x1024.jpg" alt="" width="409" height="545" srcset="https://greyli.com/wp-content/uploads/2025/11/new-flaskbook-768x1024.jpg 768w, https://greyli.com/wp-content/uploads/2025/11/new-flaskbook-113x150.jpg 113w, https://greyli.com/wp-content/uploads/2025/11/new-flaskbook-225x300.jpg 225w, https://greyli.com/wp-content/uploads/2025/11/new-flaskbook-624x832.jpg 624w" sizes="(max-width: 409px) 100vw, 409px" /></a></p>
<h2>本书主要特色</h2>
<p>这本书换了一个新书名，出于<a href="https://greyli.com/flask-book-2025-signed/#new-name">一个有点滑稽的原因</a>。书名从《Flask Web 开发实战：入门、进阶与原理解析》变成了《Flask 从入门到进阶：Python Web 开发工程化实践》。不过新的副书名也能更好的概括这本书的特点：以学习 Flask Web 开发作为脉络，你能通过这本书掌握相对完整的 Python Web 工程化实践。从 HTTP 原理到数据库 ORM，从单元测试到代码风格再到性能优化，从 Web 程序开发到 Web API 开发，最后再到不同的部署方式。如果想要深入了解框架，最后还有一章源码解析。同时用两个示例程序串起来各种不同的知识点，比如 Flask 项目的组织方式和技巧，以及 Flask 开发中各类功能的实现。</p>
<p>访问这本书的主页查看详细介绍和章节目录：<a href="https://helloflask.com/book/4/">https://helloflask.com/book/4/</a></p>
<h2>新版本主要变化</h2>
<p>下面是一些具体内容上的变化：</p>
<h3>版本升级</h3>
<table>
<thead>
<tr>
<th>旧版本</th>
<th>新版本</th>
</tr>
</thead>
<tbody>
<tr>
<td>Flask 1.x</td>
<td>Flask 3.x</td>
</tr>
<tr>
<td>Python 2.7, 3.6+</td>
<td>Python 3.9+</td>
</tr>
<tr>
<td>Bootstrap 4.x</td>
<td>Bootstrap 5.x</td>
</tr>
<tr>
<td>SQLAlchemy 1.x</td>
<td>SQLAlchemy 2.x</td>
</tr>
</tbody>
</table>
<h3>技术栈更新</h3>
<table>
<thead>
<tr>
<th>旧版本</th>
<th>新版本</th>
</tr>
</thead>
<tbody>
<tr>
<td>Pipenv</td>
<td>PDM</td>
</tr>
<tr>
<td>Flask-Mail</td>
<td>Flask-Mailman</td>
</tr>
<tr>
<td>Flake8</td>
<td>Ruff</td>
</tr>
<tr>
<td>Open Iconic</td>
<td>Bootstrap Icon</td>
</tr>
<tr>
<td>Flask-Moment + Moment.js</td>
<td>Day.js</td>
</tr>
<tr>
<td>jQuery</td>
<td>Vanilla JS</td>
</tr>
<tr>
<td>AJAX with jQuery</td>
<td>Fetch API</td>
</tr>
<tr>
<td>Flask for Web API</td>
<td>APIFlask</td>
</tr>
<tr>
<td>云平台部署</td>
<td>Docker 部署</td>
</tr>
</tbody>
</table>
<p>示例程序上做了比较大的调整，删掉了旧版本的 <a href="https://github.com/greyli/sayhello">SayHello</a>、<a href="https://github.com/greyli/todoism">Todoism</a>、<a href="https://github.com/greyli/catchat">CatChat</a>，保留两个程序并做了比较大的重构：</p>
<table>
<thead>
<tr>
<th>旧版本</th>
<th>新版本</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bluelog</td>
<td><a href="https://github.com/greyli/greybook" target="_blank" rel="noopener">Greybook</a></td>
</tr>
<tr>
<td>Albumy</td>
<td><a href="https://github.com/greyli/moments" target="_blank" rel="noopener">Moments</a></td>
</tr>
<tr>
<td>helloflask/demos</td>
<td><a href="https://github.com/greyli/helloflask/tree/main/examples" target="_blank" rel="noopener">helloflask/examples</a></td>
</tr>
</tbody>
</table>
<p>新版本计划是想做一些删减，比如从 700 页减到 500 页，毕竟一本厚书还是让人蛮有压力的。虽然删掉了两个章节，但是写到最后又快到了 700 页，实际的厚度比旧版本还要厚一点点。大概不知不觉又加了很多内容进来。</p>
<h2>面向的读者群</h2>
<p>本书面向的读者群如下：</p>
<ul>
<li>了解 Python 基本语法，想要自己动手开发网站的编程爱好者</li>
<li>熟悉 Python，想要从事 Python Web 开发的后端工程师、运维工程师和爬虫工程师</li>
<li>想要从 Django 等其他 Python Web 框架转向 Flask 的 Python 工程师</li>
</ul>
<p>本书不包含对 Python 的基础知识介绍，所以读者需要事先对 Python 基本语法有一定的了解。另外，Web 开发不可避免的会涉及到一些 HTML、CSS 和 JavaScript 知识，如果你不熟悉这些，可以通过 MDN 提供的 <a href="https://developer.mozilla.org/zh-CN/docs/learn" target="_blank" rel="noopener">Web 开发入门教程</a>学习，简单了解即可。</p>
<h2>推荐语</h2>
<blockquote>
<p>Great resources make great developers, and it’s wonderful to see Flask supported by such high-quality education materials.</p>
<p>—— <a href="https://lucumr.pocoo.org/about/">Armin Ronacher</a>（Flask 作者，Sentry Platform 副总裁）</p>
<p>作为一名对 Python 充满热忱的软件工程师，一名乐于帮助他人、回馈社区的布道者，Grey 对技术准确性、阅读体验感的无限追求都体现在这本新作中，我相信每一名读者都能在字里行间感受到他的诚意。</p>
<p>—— 管俊（《DevOps 实践指南（第 2 版）》译者，戴尔中国卓越研发集团 DevOps 架构师）</p>
<p>这本书内容翔实，推荐给想要系统学习 Flask 的人。不要漏掉书中的小知识点哦。</p>
<p>—— <a href="http://lepture.com/">Hsiaoming Yang</a>（Typlog 创始人，Authlib 作者）</p>
</blockquote>
<h2>关于作者</h2>
<p class="">我是李辉（Grey Li），Flask &amp; APIFlask 的维护者，Flask 开发团队（<a href="https://palletsprojects.com/people" target="_blank" rel="noopener">Pallets Team</a>）成员， HelloFlask 社区和代码厨房社区创建者，微软 Python 方向最有价值专家（MVP）。目前就职于戴尔中国卓越研发集团，担任首席软件工程师。</p>
<p>我热衷于开源软件的应用和推广，为 Flask 等开源项目贡献过大量代码。也曾在 PyCon China、PyCon US、COSCUP、COSCon、CommunityOverCode 等技术大会担任演讲嘉宾。你可以在 <a href="https://github.com/greyli" target="_blank" rel="noopener">GitHub</a> 上看到我的开源项目。</p>
<p>如果你想了解我的新作品或其他动态，可以关注我的 <a href="https://twitter.com/greylihui" target="_blank" rel="noopener">Twitter</a> 和<a href="https://greyli.com/files/qrcode_gh.jpg" target="_blank" rel="noopener">微信公众号</a>，或是加入我的<a href="https://greyli.com/newsletter" target="_blank" rel="noopener">邮件通讯列表</a>。</p>
<h2>勘误、分享和评价</h2>
<p>在阅读过程中如果发现了排版或内容上的错误，欢迎通过下面的方式提交勘误。我会在后续重印时进行修正。感谢反馈！</p>
<ul>
<li>提交 <a href="https://github.com/greyli/helloflask/issues/new/choose">GitHub issue</a></li>
<li>在<a href="https://codekitchen.community/t/topic/837">勘误收集帖</a>留言</li>
</ul>
<p>如果你觉得这本书还不错，欢迎分享到社交网络，或是告诉你的同事和朋友。也欢迎在<a href="https://book.douban.com/subject/37668215/">本书的豆瓣页面</a>标记和评价。</p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/new-flask-book/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>《Flask 从入门到进阶》签名版预售</title>
		<link>https://greyli.com/flask-book-2025-signed/</link>
		<comments>https://greyli.com/flask-book-2025-signed/#comments</comments>
		<pubDate>Fri, 17 Oct 2025 10:58:36 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Flask Web开发实战]]></category>
		<category><![CDATA[Flask 从入门到进阶]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=5742</guid>
		<description><![CDATA[五年了，终于等到这一天。《Flask Web 开发实战》的全新升级版《Flask 从入门到进阶：Python  [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>五年了，终于等到这一天。《Flask Web 开发实战》的全新升级版《<a href="https://helloflask.com/book/4/">Flask 从入门到进阶：Python Web 开发工程化实践</a>》将于下个月正式发售。和上一版一样，先来预售作者签名版。</p>
<h2>签名版</h2>
<p>签名版的价格和上一版保持一致，依然是 109。付款方式和详细说明可以访问预售页面查看：</p>
<p><a href="https://helloflask.com/book/4/signed/">https://helloflask.com/book/4/signed/</a></p>
<p>签名版除了送 2 张 Flask 贴纸，还会额外送一张我的名片，可以用来当书签或者飞着玩。具体发货时间取决于正式发售时间，虽然不能完全保证，但我会尽量让签名书第一批发出。</p>
<h2 id="new-name">新书名</h2>
<p>你也许好奇为什么要换一个新书名，而不是作为第 2 版出版，即《Flask Web 开发实战（第 2 版）》。我设想了一些合理解释：因为内容变动比较多，换个更贴切的书名；在副书名里加一个 Python 关键字，更容易被别人搜索到……但背后实际的乌龙是：管理书号的工作人员在录入系统时打错了名字，把《Flask Web 开发实战》写成了《Flash Web 开发实战》。</p>
<p>按照出版规定，如果我想作为原书第 2 版来出版，那么新书名就只能叫《Flash Web 开发实战（第 2 版）》了。诸位应该也不想学 Flash Web 吧？</p>
<p><a href="https://greyli.com/wp-content/uploads/2025/10/flask-book-signed-poster.jpg"><img class="aligncenter size-large wp-image-5743" src="https://greyli.com/wp-content/uploads/2025/10/flask-book-signed-poster-1024x1024.jpg" alt="" width="625" height="625" srcset="https://greyli.com/wp-content/uploads/2025/10/flask-book-signed-poster-1024x1024.jpg 1024w, https://greyli.com/wp-content/uploads/2025/10/flask-book-signed-poster-150x150.jpg 150w, https://greyli.com/wp-content/uploads/2025/10/flask-book-signed-poster-300x300.jpg 300w, https://greyli.com/wp-content/uploads/2025/10/flask-book-signed-poster-144x144.jpg 144w, https://greyli.com/wp-content/uploads/2025/10/flask-book-signed-poster-624x624.jpg 624w, https://greyli.com/wp-content/uploads/2025/10/flask-book-signed-poster.jpg 1600w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/flask-book-2025-signed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>《Flask 入门教程》第 4 版发布</title>
		<link>https://greyli.com/flask-tutorial-v4/</link>
		<comments>https://greyli.com/flask-tutorial-v4/#respond</comments>
		<pubDate>Mon, 13 Oct 2025 13:12:29 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Flask 入门教程]]></category>
		<category><![CDATA[写作]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=5732</guid>
		<description><![CDATA[即将出版的新书（预计将于本月底发售）变成了一个超强 deadline，它提及的所有东西都要在发售前成为现实。比 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>即将出版的新书（预计将于本月底发售）变成了一个超强 deadline，它提及的所有东西都要在发售前成为现实。比如写进书里但其实还不存在的 APIFlask 3.0.0 版本，以及这个可以被当作先导材料的《Flask 入门教程》。</p>
<p><span data-pm-slice="1 1 [&quot;para&quot;,{&quot;tagName&quot;:&quot;p&quot;,&quot;attributes&quot;:{&quot;style&quot;:null},&quot;namespaceURI&quot;:&quot;http://www.w3.org/1999/xhtml&quot;}]">面向 Flask 2.x 的旧版本当然没法作为先导材料，所以断断续续花了 26 个小时完成了第 4 版的更新。新版本主要有下面这些变动：</span></p>
<ul>
<li>优化全书的内容和措辞</li>
<li>增加对 uv 的介绍</li>
<li>升级到 SQLAlchemy 2.x</li>
<li>针对 Flask 3.1.x 进行内容更新</li>
<li>Python 支持版本调整为 3.9+</li>
<li>增加对蓝本、工厂函数的介绍</li>
</ul>
<p>另外正式加了一章介绍为什么以及如何为本书付费，取代了主页上自愿点击的「付费支持￥10」按钮。考虑到整本书内容完全公开，所以<span data-pm-slice="1 1 [&quot;para&quot;,{&quot;tagName&quot;:&quot;p&quot;,&quot;attributes&quot;:{&quot;style&quot;:null},&quot;namespaceURI&quot;:&quot;http://www.w3.org/1999/xhtml&quot;}]">没法阻止读者逃票，但至少我已经克服了「伸手要钱」的羞耻。</span>对于在工作之外挤出的这些时间，我需要一些正反馈。这样可以让自己更认真维护下去，也不会产生怨念。不仅是获得收入，有时还会收到读者的附言感谢，这给我的生活里带来了很多随机的开心时刻。<a href="https://greyli.com/wp-content/uploads/2025/10/feedback.png"><img class="wp-image-5736 aligncenter" src="https://greyli.com/wp-content/uploads/2025/10/feedback-517x1024.png" alt="" width="253" height="501" srcset="https://greyli.com/wp-content/uploads/2025/10/feedback-517x1024.png 517w, https://greyli.com/wp-content/uploads/2025/10/feedback-76x150.png 76w, https://greyli.com/wp-content/uploads/2025/10/feedback-151x300.png 151w, https://greyli.com/wp-content/uploads/2025/10/feedback-624x1236.png 624w, https://greyli.com/wp-content/uploads/2025/10/feedback.png 862w" sizes="(max-width: 253px) 100vw, 253px" /></a></p>
<p>写新版本的过程中有时也会想，现在跟 AI 说一句「帮我用 Flask 写一个 Watchlist 程序」就大概能实现的程序，还有人愿意来读教程吗？我想至少，在通过教程来学习编程可以让你说一句「我真厉害」，而不仅仅是一句「AI 真厉害」。</p>
<p>另外这个教程最早是在 2019 年发布的，六年过去了，部署章节介绍的 <a href="https://www.pythonanywhere.com/">PythonAnywhere</a> 的 UI 和功能基本没有任何改变。我只需要更新 Python 版本选择那个页面的图片，其他部分不需要任何改动。有一种值得托付终生的感觉。希望可以做出来有这样品质的产品和作品。</p>
<p>最后附上相关链接：</p>
<ul>
<li>主页：<a href="https://helloflask.com/book/3" rel="nofollow">https://helloflask.com/book/3</a></li>
<li>阅读：<a href="https://tutorial.helloflask.com/" rel="nofollow">https://tutorial.helloflask.com/</a></li>
<li>书稿更新 PR：<a href="https://github.com/helloflask/flask-tutorial/pull/38">https://github.com/helloflask/flask-tutorial/pull/38</a></li>
<li>示例程序更新 PR：<a href="https://github.com/helloflask/watchlist/pull/21">https://github.com/helloflask/watchlist/pull/21</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/flask-tutorial-v4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flask 已死，FastAPI 永生</title>
		<link>https://greyli.com/flask-fastapi-2023/</link>
		<comments>https://greyli.com/flask-fastapi-2023/#comments</comments>
		<pubDate>Sat, 23 Dec 2023 08:43:27 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[FastAPI]]></category>
		<category><![CDATA[Flask]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=5306</guid>
		<description><![CDATA[好险，刚刚要写一个新项目，执行了 pip install flask。等得无聊所以打开了知乎，突然看到首页推荐 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>好险，刚刚要写一个新项目，执行了 pip install flask。等得无聊所以打开了知乎，突然看到首页推荐的这篇《<a href="https://zhuanlan.zhihu.com/p/672806587">Flask 已死，FastAPI 是未来</a>》。看到一半吓得我赶紧按下 Ctrl-C，然后重新执行了 pip install fastapi。好快！不愧是 FastAPI，连安装都这么快。</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/zhihu.png"><img class="aligncenter size-large wp-image-5322" src="https://greyli.com/wp-content/uploads/2023/12/zhihu-1024x966.png" alt="" width="625" height="590" srcset="https://greyli.com/wp-content/uploads/2023/12/zhihu-1024x966.png 1024w, https://greyli.com/wp-content/uploads/2023/12/zhihu-150x141.png 150w, https://greyli.com/wp-content/uploads/2023/12/zhihu-300x283.png 300w, https://greyli.com/wp-content/uploads/2023/12/zhihu-624x588.png 624w, https://greyli.com/wp-content/uploads/2023/12/zhihu.png 1440w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<p>Flask！Flask！你怎么了？Flask~Flask~你不能死呀！我跟你相依为命、同甘共苦了这么多年，何况<a href="https://helloflask.com/book/4/" target="_blank" rel="noopener">我的书</a>还没有写完，想不到今天白发人送黑发人……</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/flask-dont-die-sm.png"><img class="aligncenter size-full wp-image-5329" src="https://greyli.com/wp-content/uploads/2023/12/flask-dont-die-sm.png" alt="" width="1000" height="609" srcset="https://greyli.com/wp-content/uploads/2023/12/flask-dont-die-sm.png 1000w, https://greyli.com/wp-content/uploads/2023/12/flask-dont-die-sm-150x91.png 150w, https://greyli.com/wp-content/uploads/2023/12/flask-dont-die-sm-300x183.png 300w, https://greyli.com/wp-content/uploads/2023/12/flask-dont-die-sm-624x380.png 624w" sizes="(max-width: 1000px) 100vw, 1000px" /></a></p>
<p>咳咳，说回正题，2021 年我写过一篇《<a href="https://greyli.com/flask-fastapi/">请不要把 Flask 和 FastAPI 放到一起比较</a>》。不是同一个等级的框架拿到一起比较没有意义。这篇《<a class="internal" href="https://zhuanlan.zhihu.com/p/672806587" target="_blank" rel="noopener">Flask 已死，FastAPI 是未来</a>》从一开始的标题就是错的。</p>
<p>除了比较上的问题，上一篇文章里最后提的问题现在有答案了吗？</p>
<blockquote><p>各种对比文章贴出来的 hello world benchmark 对于开发生产应用来说有多大的意义？这里的 benchmark 背后有没有任何的 hacky？异步是否等同于高性能还是要看情况？框架本身的性能在一个请求处理流程中占多大的影响？asyncio 的生态怎么样？</p></blockquote>
<p>同时我也指出了一些 FastAPI 的问题——现在 FastAPI 营销至上的项目运作方式改变了吗？</p>
<blockquote><p>从长远看这些大都是一些临时问题，而且 FastAPI 作者已经开始全职开发开源项目，这些问题在未来应该都会慢慢得到改善。指出这些是希望更多的人可以客观看待 FastAPI，吹捧并不能让一个东西变得更好，参与开发、介绍用法和回答社区提问是比盲目吹捧更有意义的事情。我当然期待 FastAPI 能够越来越好，也期待看到有更多优秀的 Python 框架出现，但我不喜欢过度炒作、盲目的吹捧和错误的对比。</p></blockquote>
<p>如果一个人即没有深入了解 Flask，也对 FastAPI 的整体状况一知半解，然后突然跳出来写了一篇《Flask 已死，FastAPI 是未来》，他的目的是什么？炒作啊，朋友。标题党也就罢了，到处都是逻辑漏洞和事实错误这也行？</p>
<h3>精彩片段赏析</h3>
<p>前两天在 Twitter 上对这篇文章发了<a class=" wrap external" href="https://twitter.com/greylihui/status/1737638967233974656" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">一点想法</a>。大概是我的语言能力退化，导致很多人没看懂我的反讽和调侃……所以还是好好说话，摘评几条原文的内容：</p>
<blockquote><p><b>其实我这篇文章，也可以叫做「Django和Flask之死」，但是在框架应用场景角度来说Flask和FastAPI对比更合适，而Django直接和FastAPI相比有一些差别。</b>在一些商业场景(例如CMS)Django依然是首选，而Flask(甚至FastAPI)看起来更像个「玩具」，所以Django短时间不会被取代(Flask这些年不是也是没取代的了嘛)。<br />
Django REST Framework(DRF)<br />
Django主旨是为了在后端生成 HTML，而不是创建现代前端（如 React、Vue.js ）或与其通信的其他系统使用的 API。<b>所以FastAPI其实和Django REST Framework直接对标，它们主要场景都是构建 Web API</b>，但是名字上也可以看出来，DRF还是依托于Django框架，所以缺点一样。</p></blockquote>
<p>既然作者能看出来 Django 和 FastAPI 有差别，也了解「FastAPI其实和Django REST Framework直接对标」，那么就看不出来 Flask 和 FastAPI 在框架应用场景角度有差别？所以为什么不用 APIFlask 这种和 FastAPI 对标的框架，而是挑了 Flask？</p>
<blockquote data-pid="7o4al8QO"><p>Flask本来的优点是灵活性和极简主义，但这意味着很多很多组件需要自己造，这个要不然需要公司够大专门有开发者开发和维护，要不然得个人能力极强，否则插件很难达到生产级别，这就造成Flask的第三方插件质量层次不齐，且无法保证长期维护。就像我上面说的那些库，现在来看，其中已经很多不再维护了。</p></blockquote>
<p>这点蛮中肯，Flask 扩展的质量和维护状态确实参差不齐，这也是为什么我要发起<a class=" wrap external" href="https://www.bilibili.com/video/BV1Ac411q7qY/" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">濒危 Flask 扩展拯救计划</a>并创建这个 <a class=" wrap external" href="https://github.com/greyli/flask-extension-status" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Flask 扩展状态监控项目</a>。那请问 FastAPI 呢？首先 FastAPI 是否有这么多「FastAPI 扩展」可用？其次 FastAPI 的第三方插件就不会出现这些问题？说到底这是所有开源项目和社区生态都会遇到的问题。</p>
<blockquote><p>所以即便是今天，你想用Flask构建一个API服务，还是要东拼西凑各个组件，其中某些组件有些没及时更新的地方要自己动手解决，这对于老手来说还好，对于新人来说很痛苦，尤其是你想要应用现在最新的实践方案和理念，只能望而兴叹。</p></blockquote>
<p>首先作者了解 Flask 和 FastAPI 相比，后者的主要场景是「主要场景都是构建 Web API」，接着又说 Flask 生态构建 API 需要东拼西凑。听起来不太对劲？</p>
<p>另外 Flask 生态中类似 FastAPI 这种提供 API 整体解决方案的框架都被作者忽略了？随便列几个：</p>
<ul>
<li><a class=" wrap external" href="https://github.com/miguelgrinberg/APIFairy" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">APIFairy</a></li>
<li><a class=" wrap external" href="https://github.com/apiflask/apiflask" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">APIFlask</a></li>
<li><a class=" wrap external" href="https://github.com/zalando/connexion" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Connexion</a></li>
<li data-pid="ANwYCDaQ"><a class=" wrap external" href="https://github.com/pyeve/eve" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Eve</a></li>
<li><a class=" wrap external" href="https://github.com/python-restx/flask-restx" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Flask-RESTX</a></li>
<li data-pid="Y0gee2BD"><a class=" wrap external" href="https://github.com/marshmallow-code/flask-smorest" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Flask-Smorest</a></li>
<li><a class=" wrap external" href="https://github.com/plangrid/flask-rebar" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Flask-Rebar</a></li>
<li><a class=" wrap external" href="https://github.com/0b01001001/spectree" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">SpecTree</a></li>
</ul>
<p>东拼西凑就一定是缺点？不熟悉这些工具的人选择打包方案，熟悉的人选择自己组装，这有什么问题吗？</p>
<blockquote><p>这个时候Flask并不想接受改变，社区迟迟的不加入aio的支持，另外Flask原作者也去写rust了，把项目交给了2个维护者（现在只剩一个人了)。</p></blockquote>
<p>到这里文章就开始有些不对劲了，喜剧/戏剧效果逐渐增加……Flask 开始被拟人化了。Flask 是谁？是谁要求改变？Flask 说了啥表示不想改变？</p>
<p>Flask 作者把项目交给了 2 个维护者？现在只剩一个人了？！Flask 真的好惨……可是这些事情都是什么时候发生的？虽然我最近两年开始工作已经没怎么给 Flask 提交代码，不知道哪天被踢出群聊。但是至少我从 18 年到现在一直是 <a class=" wrap external" href="https://palletsprojects.com/people/greyli/" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Flask 的维护者</a>，这些事情我怎么一点都不知道？</p>
<blockquote><p>在Flask的那个时代，代码执行是单线程、同步的，这意味着要依次处理请求，前一个请求完成前，其他请求消耗在等待 I/O 操作上。而asyncio是最好的解决方案，它让I/O成为异步操作，无需等待任务完成即可获取任务结果并继续处理其他任务请求。</p></blockquote>
<p>好奇 Flask 的那个时代是哪个时代呀？听起来像是妈妈在讲小时候的故事呢。Flask 2.0 已经添加了<a class=" wrap external" href="https://flask.palletsprojects.com/en/3.0.x/async-await/" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">有限的 async 支持</a>。<a class=" wrap external" href="https://github.com/pallets/quart" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Quart</a> （Flask 的 ASGI 实现）已经合并到 pallets 组织，作者正在推动 ASGI 支持的 Flask。这些都是这个时代的 Flask 在发生的事情哦。</p>
<blockquote><p>而FastAPI天生支持并发和异步代码，代码写对了就可以在效率上达到极致，所以它被认为是目前最快的Python框架，效率和NodeJS或Go接近。当速度和性能至关重要时，FastAPI 是最佳选择。</p></blockquote>
<p>嗯，这个我无从反驳。你说快就是快，宇宙最快 Web 框架。</p>
<blockquote data-pid="n4C1OgOd"><p>另外由于集成了Pydantic，所以非常容易在项目中添加ORM（如<a class=" wrap external" href="https://www.sqlalchemy.org/" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">SQLAlchemy</a>），从请求中获得的对象可以直接传递到数据库，因为已经做过数据验证。反之亦然，可以将从数据库获取的对象直接返回。<br />
<b>相对的，Flask这方面的缺失的。</b></p></blockquote>
<p>完蛋，Pydantic 对 Flask 发起了单方面安装制裁。当你在 Flask 项目里试图引入 Pydantic 的时候，就会出现安装错误“Warnning: Pydantic is strictly forbidden to installed into a Flask project. Your behavior has been reported to PAFAFC (Pydantic and FastAPI and friends Committee).”</p>
<blockquote><p>再补充一点。<b>FastAPI无论看项目名字还是介绍都能感觉出来它是用于构建API服务的</b>，事实上FastAPI自己的核心代码也确实是这样的，可以说它不是一个传统的、完全自己实现的框架，它更像是一个集各家之长的框架，从一个空壳开始，把需要的、适合的组件组装起来。例如它没有模版引擎，如果你确实需要用它实现一个web应用要渲染模版，<b>你可以再组合你想要的选择，当然还可以用Starlette内置的Jinja2（是的，也是Flask内置的）</b>。</p></blockquote>
<p>作者对于 Flask 和 FastAPI 两者定位不同的认识真是越来越清晰了呢。不过「组合我想要的选择」不就变成前面说的 Flask 那样东拼西凑了嘛，不好。还有就是 FastAPI 为啥要在<a class=" wrap external" href="https://fastapi.tiangolo.com/advanced/templates/" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">介绍模板引擎的文档</a>里让我安装 Jinja2 呢？看来「相对的，FastAPI这方面是缺失的」。</p>
<blockquote><p>上面提的是FastAPI的优势，但是也不能说明Flask已死，我为什么会这么觉得呢? 主要还是看开发者和用户的人气。</p></blockquote>
<p>重头戏来了，下面终于到了对于「Flask 之死」的凄惨景观的详细描写（注：这几点后来作者看到了我在 Twitter 上发的东西又自己做了补充和修改。这里我引用的是<a class=" wrap external" href="https://boblin.app/posts/flask-is-dead-you-should-use-fastapi/" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">原文</a>）。</p>
<blockquote><p>1. 社区活跃度。<b>例如项目的Issue和Pull Request数量，Flask都是个位数，和FastAPI相比根本不是一个水平。这其实侧面证明项目不再活跃</b>，因为如果活跃的话，老的用户会有更多需求，它们不来说明已经离开，而新的用户意味着有各种问题，文档即便足够全，其实我们要知道还是会有很多用户来提问和贡献代码的，<b>没有就说明用得少。</b></p></blockquote>
<p>如果你经常参与开源项目或是自己开发了开源项目，通常会了解到，一个流行的项目想要把所有的 issue 和 pull request 都处理掉是很难的事情。而 Flask 能做到这一点反而是维护团队的努力尽责和项目本身足够成熟的体现：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/twitter1.png"><img class="aligncenter  wp-image-5321" src="https://greyli.com/wp-content/uploads/2023/12/twitter1-1024x841.png" alt="" width="503" height="413" srcset="https://greyli.com/wp-content/uploads/2023/12/twitter1-1024x841.png 1024w, https://greyli.com/wp-content/uploads/2023/12/twitter1-150x123.png 150w, https://greyli.com/wp-content/uploads/2023/12/twitter1-300x246.png 300w, https://greyli.com/wp-content/uploads/2023/12/twitter1-624x512.png 624w, https://greyli.com/wp-content/uploads/2023/12/twitter1.png 1292w" sizes="(max-width: 503px) 100vw, 503px" /></a></p>
<p>以及对 issue 和 pull request 快速响应的体现：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/twitter2.png"><img class="aligncenter  wp-image-5320" src="https://greyli.com/wp-content/uploads/2023/12/twitter2-1024x868.png" alt="" width="447" height="379" srcset="https://greyli.com/wp-content/uploads/2023/12/twitter2-1024x868.png 1024w, https://greyli.com/wp-content/uploads/2023/12/twitter2-150x127.png 150w, https://greyli.com/wp-content/uploads/2023/12/twitter2-300x254.png 300w, https://greyli.com/wp-content/uploads/2023/12/twitter2-624x529.png 624w, https://greyli.com/wp-content/uploads/2023/12/twitter2.png 1293w" sizes="(max-width: 447px) 100vw, 447px" /></a></p>
<p>如果你想知道有多少人在用 Flask 和 FastAPI，有两个参考数据，一个是 GitHub 上开源项目的用户数量统计。这些可以在两个项目的 GitHub 主页直接看到。</p>
<p><a class=" wrap external" href="https://github.com/tiangolo/fastapi" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">FastAPI</a>：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/fastapi-download.png"><img class="aligncenter  wp-image-5319" src="https://greyli.com/wp-content/uploads/2023/12/fastapi-download.png" alt="" width="487" height="141" srcset="https://greyli.com/wp-content/uploads/2023/12/fastapi-download.png 622w, https://greyli.com/wp-content/uploads/2023/12/fastapi-download-150x43.png 150w, https://greyli.com/wp-content/uploads/2023/12/fastapi-download-300x87.png 300w" sizes="(max-width: 487px) 100vw, 487px" /></a></p>
<p><a class=" wrap external" href="https://github.com/pallets/flask" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Flask</a>：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/flask-download.png"><img class="aligncenter  wp-image-5318" src="https://greyli.com/wp-content/uploads/2023/12/flask-download.png" alt="" width="500" height="161" srcset="https://greyli.com/wp-content/uploads/2023/12/flask-download.png 636w, https://greyli.com/wp-content/uploads/2023/12/flask-download-150x48.png 150w, https://greyli.com/wp-content/uploads/2023/12/flask-download-300x96.png 300w, https://greyli.com/wp-content/uploads/2023/12/flask-download-624x200.png 624w" sizes="(max-width: 500px) 100vw, 500px" /></a></p>
<p>另一个数据是 PyPI 下载量，这个可以在 <a class=" wrap external" href="https://pypistats.org/" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">PyPI Download Stats</a> 上看到。</p>
<p><a href="https://pypistats.org/packages/fastapi">FastAPI</a>：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/fastapi-pypi-download.png"><img class="aligncenter size-large wp-image-5317" src="https://greyli.com/wp-content/uploads/2023/12/fastapi-pypi-download-1024x383.png" alt="" width="625" height="234" srcset="https://greyli.com/wp-content/uploads/2023/12/fastapi-pypi-download-1024x383.png 1024w, https://greyli.com/wp-content/uploads/2023/12/fastapi-pypi-download-150x56.png 150w, https://greyli.com/wp-content/uploads/2023/12/fastapi-pypi-download-300x112.png 300w, https://greyli.com/wp-content/uploads/2023/12/fastapi-pypi-download-624x234.png 624w, https://greyli.com/wp-content/uploads/2023/12/fastapi-pypi-download.png 1440w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<p><a href="https://pypistats.org/packages/flask">Flask</a>：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/flask-pypi-download.png"><img class="aligncenter size-large wp-image-5316" src="https://greyli.com/wp-content/uploads/2023/12/flask-pypi-download-1024x565.png" alt="" width="625" height="345" srcset="https://greyli.com/wp-content/uploads/2023/12/flask-pypi-download-1024x565.png 1024w, https://greyli.com/wp-content/uploads/2023/12/flask-pypi-download-150x83.png 150w, https://greyli.com/wp-content/uploads/2023/12/flask-pypi-download-300x165.png 300w, https://greyli.com/wp-content/uploads/2023/12/flask-pypi-download-624x344.png 624w, https://greyli.com/wp-content/uploads/2023/12/flask-pypi-download.png 1356w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<p>另一方面，不同的项目对 issue 的使用策略是不同的。有的使用自己的 issue tracker，有些鼓励用户来提问。Issue 和 pull requests 不仅不能用来表示项目活跃度，过多的数量反而能说明一个项目的维护状况堪忧。堆积的 PR 对于用户和开发者来说都是灾难。以 FastAPI 为例，你看看<a class=" wrap external" href="https://github.com/tiangolo/fastapi/pulls" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">现在的 PR 列表</a>里都是什么？项目不如改名叫「FastAPI 文档大全」好了。你觉得这样会让提交代码贡献，修复 bug 的人有很好的体验？</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/fastapi-pr.png"><img class="aligncenter size-large wp-image-5315" src="https://greyli.com/wp-content/uploads/2023/12/fastapi-pr-1024x737.png" alt="" width="625" height="450" srcset="https://greyli.com/wp-content/uploads/2023/12/fastapi-pr-1024x737.png 1024w, https://greyli.com/wp-content/uploads/2023/12/fastapi-pr-150x108.png 150w, https://greyli.com/wp-content/uploads/2023/12/fastapi-pr-300x216.png 300w, https://greyli.com/wp-content/uploads/2023/12/fastapi-pr-624x449.png 624w, https://greyli.com/wp-content/uploads/2023/12/fastapi-pr.png 1440w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<p>FastAPI 有不少 issue 在建议作者创建开发团队，摆脱当前这种低效的维护模式。类似的抱怨有很多，我不想去翻历史，这里仅以<a class=" wrap external" href="https://github.com/tiangolo/fastapi/issues/10370%23issuecomment-1762749084" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">置顶 issue 里的一则回复</a>举例：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/fastapi-comment1.png"><img class="aligncenter size-large wp-image-5314" src="https://greyli.com/wp-content/uploads/2023/12/fastapi-comment1-1024x760.png" alt="" width="625" height="464" srcset="https://greyli.com/wp-content/uploads/2023/12/fastapi-comment1-1024x760.png 1024w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment1-150x111.png 150w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment1-300x223.png 300w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment1-624x463.png 624w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment1.png 1213w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<p>评论中提到的是<a class=" wrap external" href="https://github.com/tiangolo/fastapi/pull/5707" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">这个 PR</a>。一个 bug 在 2022 年就有人试图修复，但是到现在都没有被处理。而且报告相关 bug 的 issue 已经被转换成<a class=" wrap external" href="https://github.com/tiangolo/fastapi/discussions/8424" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">讨论</a>。最后一条是用户在建议把这个讨论转换回 issue：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/fastapi-comment2.png"><img class="aligncenter size-large wp-image-5313" src="https://greyli.com/wp-content/uploads/2023/12/fastapi-comment2-1024x228.png" alt="" width="625" height="139" srcset="https://greyli.com/wp-content/uploads/2023/12/fastapi-comment2-1024x228.png 1024w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment2-150x33.png 150w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment2-300x67.png 300w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment2-624x139.png 624w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment2.png 1440w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<p>没错，FastAPI 本来有几百个 issue（好活跃，对吧），某个时间点被批量转换为讨论，谁知道里面有多少是没有被处理的 bug report。谁知道这 646 个 PR 里有多少是需要被优先处理的 PR。我在 2020 年也提议<a class=" wrap external" href="https://github.com/tiangolo/fastapi/discussions/7094" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">把文档翻译放到单独的仓库</a>，后来这个 issue 也被转成讨论了。到现在贡献者依然<a class=" wrap external" href="https://github.com/tiangolo/fastapi/pull/10638%23issuecomment-1838107879" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">被这个问题困扰</a>：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/fastapi-comment3.png"><img class="aligncenter size-large wp-image-5312" src="https://greyli.com/wp-content/uploads/2023/12/fastapi-comment3-1024x347.png" alt="" width="625" height="212" srcset="https://greyli.com/wp-content/uploads/2023/12/fastapi-comment3-1024x347.png 1024w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment3-150x51.png 150w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment3-300x102.png 300w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment3-624x211.png 624w, https://greyli.com/wp-content/uploads/2023/12/fastapi-comment3.png 1229w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<blockquote><p>2. 讨论度。也就是<b>博客文章，Stackoverflow等网站咨询和讨论的热度</b>，其实可以感受到，已经没什么人写Flask相关的内容了。</p></blockquote>
<p>作者写文章是可以随口就来的？博客文章不好统计，那么以 Stack Overflow 来看。抛开问题总数量，因为两个项目创建时间不同。但就提问频率，以上次发推文和现在两次截图的数据来看，和 Flask 相关的问题都创建的更频繁。</p>
<p><a class=" wrap external" href="https://stackoverflow.com/questions/tagged/fastapi" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">FastAPI</a>：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/fastapi-so.png"><img class="aligncenter size-large wp-image-5311" src="https://greyli.com/wp-content/uploads/2023/12/fastapi-so-1024x876.png" alt="" width="625" height="535" srcset="https://greyli.com/wp-content/uploads/2023/12/fastapi-so-1024x876.png 1024w, https://greyli.com/wp-content/uploads/2023/12/fastapi-so-150x128.png 150w, https://greyli.com/wp-content/uploads/2023/12/fastapi-so-300x257.png 300w, https://greyli.com/wp-content/uploads/2023/12/fastapi-so-624x534.png 624w, https://greyli.com/wp-content/uploads/2023/12/fastapi-so.png 1440w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<p><a class=" wrap external" href="https://stackoverflow.com/questions/tagged/flask" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">Flask</a>：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/flask-so.png"><img class="aligncenter size-large wp-image-5310" src="https://greyli.com/wp-content/uploads/2023/12/flask-so-1024x866.png" alt="" width="625" height="529" srcset="https://greyli.com/wp-content/uploads/2023/12/flask-so-1024x866.png 1024w, https://greyli.com/wp-content/uploads/2023/12/flask-so-150x127.png 150w, https://greyli.com/wp-content/uploads/2023/12/flask-so-300x254.png 300w, https://greyli.com/wp-content/uploads/2023/12/flask-so-624x528.png 624w, https://greyli.com/wp-content/uploads/2023/12/flask-so.png 1440w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<blockquote><p>3. 开发迭代的频率。翻一下commits，可以看到<b>Flask只有一个维护者会偶尔修修bug，没有什么大的功能特性开发。</b></p></blockquote>
<p>开发迭代的频率和活跃度也是作者强行建立的联系，不过结合 FastAPI 的运作方式，两位作者倒也是「双向奔赴」了。「偶尔修修bug，没有什么大的功能特性开发」有什么问题吗？这就是维护者应该做的事情，大的功能特性又不是每天都有。而且作者是不是没有看 FastAPI 的 <a class=" wrap external" href="https://github.com/tiangolo/fastapi/commits/master/" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">commits 历史</a>？你肯定猜不到三千多个 commits 里有<a class=" wrap external" href="https://github.com/search%3Fq%3Drepo%253Atiangolo%252Ffastapi%2Brelease%2Bnotes%26type%3Dcommits%26p%3D1" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">一千多是 bot 在更新 changelog</a>。再猜猜 FastAPI <a class=" wrap external" href="https://github.com/tiangolo/fastapi/releases/tag/0.105.0" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">最新一个 release</a> 都有哪些新功能？11 个改动里有 5 个是在更新 README 上的赞助商列表哦：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/fastapi-release.png"><img class="aligncenter size-large wp-image-5309" src="https://greyli.com/wp-content/uploads/2023/12/fastapi-release-1024x806.png" alt="" width="625" height="492" srcset="https://greyli.com/wp-content/uploads/2023/12/fastapi-release-1024x806.png 1024w, https://greyli.com/wp-content/uploads/2023/12/fastapi-release-150x118.png 150w, https://greyli.com/wp-content/uploads/2023/12/fastapi-release-300x236.png 300w, https://greyli.com/wp-content/uploads/2023/12/fastapi-release-624x491.png 624w, https://greyli.com/wp-content/uploads/2023/12/fastapi-release.png 1440w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<blockquote><p>4. 灵魂人物的影响力。Flask的灵魂人物，也就是项目的发起人其实早就不再参与项目了，搜一下项目贡献记录可以看到Armin Ronacher上次参与开发已经是6年前了。</p></blockquote>
<p>这条实在不知道说什么好。我创建了项目我就得绑死在项目上直到生命最后一刻是吗？引用一下我在 Twitter 上的回复：</p>
<blockquote><p>开源项目一定不要创建 GitHub org，项目再流行也要放在自己的账号下。不要成立什么开发团队，PR 要自己慢慢 review，用户抱怨多了，你自然知道哪个 PR 比较重要。还有就是用自己的账号或头像来设置 bot，这样即使你哪天兴趣转移了，用户会以为你一直在参与。斯人已去，灵魂犹在。</p></blockquote>
<p>我真的佩服 FastAPI 作者这一招<a class=" wrap external" href="https://github.com/tiangolo/fastapi/pull/10666" target="_blank" rel="nofollow noopener noreferrer" data-za-detail-view-id="1043">用自己的账号来作为 bot</a>，用户以为你在活跃，而这个 PR 哪天能够被 merge 还要多烧几炷香：</p>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/fastapi-bot.png"><img class="aligncenter size-large wp-image-5308" src="https://greyli.com/wp-content/uploads/2023/12/fastapi-bot-984x1024.png" alt="" width="625" height="650" srcset="https://greyli.com/wp-content/uploads/2023/12/fastapi-bot-984x1024.png 984w, https://greyli.com/wp-content/uploads/2023/12/fastapi-bot-144x150.png 144w, https://greyli.com/wp-content/uploads/2023/12/fastapi-bot-288x300.png 288w, https://greyli.com/wp-content/uploads/2023/12/fastapi-bot-624x649.png 624w, https://greyli.com/wp-content/uploads/2023/12/fastapi-bot.png 1211w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
<p>一边说自己忙得不行，一边又坚持把项目放在自己个人账号下，坚持自己 review PR。这就是灵魂人物？</p>
<h3>后记</h3>
<p>终于写完了。没想到只是偶然在一台没有屏蔽推荐首页的电脑上打开了知乎，最后要浪费这么多时间和精力。我想肯定会有人看了开头就急着评论，说「FastAPI 如何好用」或是「Flask 如何不好用」甚至是「Python 不如 XXX」。这些都是离题的讨论，我不完全否认这些观点，也并没有谈及这些。这篇文章只有两个目的：</p>
<ul>
<li>强调不应该把两者放到一起比较</li>
<li>指出那篇「引战文」中的错误观点和事实偏差，顺便指出一些 FastAPI 的问题</li>
</ul>
<p>对于程序员来说，你可以使用任何框架，你也可以使用任何编程语言。程序员不就是要随时接受改变，随时学习新的东西吗？没人要你一辈子只能用 Flask 或是 Python。另一方面，即使别人都用 FastAPI 了，我用 Flask 又会怎么样？工具而已，只是按照需要做出适当或喜欢的选择。但是你起码要看一看文章再发表评论，而且也不用看到什么观点就相信什么观点（尤其是没有论据、结论先行的文章）。</p>
<p>同时建议 FastAPI 推介者保留一点体面。新事物的建立不一定要踩在已有事物的坟墓上。挑起对立只会导致 Python 社区的混乱。最后再引述我在上一篇文章的想法作结：</p>
<blockquote><p>从长远看这些大都是一些临时问题，而且 FastAPI 作者已经开始全职开发开源项目，这些问题在未来应该都会慢慢得到改善。指出这些是希望更多的人可以客观看待 FastAPI，吹捧并不能让一个东西变得更好，参与开发、介绍用法和回答社区提问是比盲目吹捧更有意义的事情。我当然期待 FastAPI 能够越来越好，也期待看到有更多优秀的 Python 框架出现，但我不喜欢过度炒作、盲目的吹捧和错误的对比。</p></blockquote>
<hr />
<p>相关链接</p>
<ul>
<li><a href="https://zhuanlan.zhihu.com/p/673774673">本文在知乎上的讨论</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/flask-fastapi-2023/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>PyCon China 2023：濒危 Flask 扩展拯救计划</title>
		<link>https://greyli.com/pycon-china-2023-talk/</link>
		<comments>https://greyli.com/pycon-china-2023-talk/#comments</comments>
		<pubDate>Sun, 10 Dec 2023 15:17:28 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[PyCon]]></category>
		<category><![CDATA[PyCon China]]></category>
		<category><![CDATA[PyCon China 2023]]></category>
		<category><![CDATA[开源]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=5283</guid>
		<description><![CDATA[月初参加了 PyCon China 2023， 做了一个关于 Flask 扩展生态的演讲。不太算是技术分享，讲 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>月初参加了 <a href="https://cn.pycon.org/2023/">PyCon China 2023</a>， 做了一个关于 Flask 扩展生态的演讲。不太算是技术分享，讲故事为主。主要的契机是最近尝试把几个失去维护的 Flask 扩展通过各种方式「救」了回来，所以借此机会分享一下经验，也号召大家多多参与开源项目。</p>
<h2>演讲介绍</h2>
<p>看着一个又一个 Flask 扩展失去维护，不再兼容新版本的 Python 和 Flask，我们能做些什么？在这个演讲里，我会介绍最近我和一些被遗弃的 Flask 扩展打交道的经历，包括如何更新一个古老的 Python 开源项目，以及正在实施中的一个拯救计划。如果你来自其他开源社区，那么这里介绍的经验或许也会帮到你。</p>
<h2>录像和幻灯片</h2>
<ul>
<li>录像：<a href="https://www.youtube.com/watch?v=lkw9Rhjf6C8">YouTube</a> | <a href="https://www.bilibili.com/video/BV1Ac411q7qY">bilibili</a></li>
<li>幻灯片：<a href="https://greyli.com/slides/pyconchina2023">https://greyli.com/slides/pyconchina2023</a></li>
<li>演讲中提到的 Flask 扩展健康监控项目：<a href="https://github.com/greyli/flask-extension-status">https://github.com/greyli/flask-extension-status</a></li>
</ul>
<p>P.S. bilibili 认定金正恩的照片是违禁图片，留半秒都不行，最后只好贴了一只马在上面。浪费二十分钟。</p>
<h2>照片</h2>
<p><a href="https://greyli.com/wp-content/uploads/2023/12/flask-talk.jpg"><img class="aligncenter size-large wp-image-5284" src="https://greyli.com/wp-content/uploads/2023/12/flask-talk-1024x683.jpg" alt="" width="625" height="417" srcset="https://greyli.com/wp-content/uploads/2023/12/flask-talk-1024x683.jpg 1024w, https://greyli.com/wp-content/uploads/2023/12/flask-talk-150x100.jpg 150w, https://greyli.com/wp-content/uploads/2023/12/flask-talk-300x200.jpg 300w, https://greyli.com/wp-content/uploads/2023/12/flask-talk-624x416.jpg 624w" sizes="(max-width: 625px) 100vw, 625px" /></a> <a href="https://greyli.com/wp-content/uploads/2023/12/flask-talk2.jpg"><img class="aligncenter size-large wp-image-5285" src="https://greyli.com/wp-content/uploads/2023/12/flask-talk2-1024x683.jpg" alt="" width="625" height="417" srcset="https://greyli.com/wp-content/uploads/2023/12/flask-talk2-1024x683.jpg 1024w, https://greyli.com/wp-content/uploads/2023/12/flask-talk2-150x100.jpg 150w, https://greyli.com/wp-content/uploads/2023/12/flask-talk2-300x200.jpg 300w, https://greyli.com/wp-content/uploads/2023/12/flask-talk2-624x416.jpg 624w" sizes="(max-width: 625px) 100vw, 625px" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/pycon-china-2023-talk/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>戴尔 EMC Python/Go 职位内推</title>
		<link>https://greyli.com/dell-python-jobs/</link>
		<comments>https://greyli.com/dell-python-jobs/#comments</comments>
		<pubDate>Sun, 17 Jul 2022 05:05:43 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[Dell]]></category>
		<category><![CDATA[Dell EMC]]></category>
		<category><![CDATA[EMC]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[内推]]></category>
		<category><![CDATA[工作]]></category>
		<category><![CDATA[戴尔]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=4428</guid>
		<description><![CDATA[内推的最新状态见 greyli.com/dell-jobs。如果你在戴尔招聘网站上发现了其他方向/城市的意向职 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>内推的最新状态见 <a href="/dell-jobs">greyli.com/dell-jobs</a>。如果你在<a href="https://jobs.dell.com/">戴尔招聘网站</a>上发现了其他方向/城市的意向职位，也可以联系我内推。</p>
<hr />
<p>最近公司又开放了几个新的 Python/Go 职位空缺，如果感兴趣的话，一起来做同事吧。</p>
<p>职位要求：</p>
<ul>
<li>计算机相关学士学位或 1~2 年软件开发经验（另外还有对应 3~5 年以及 10 年以上经验的职位）</li>
<li>熟悉 Python/Go/Java（任一，最好是 Python/Go 方向）</li>
<li>熟悉 Linux 和 Git 的使用</li>
<li>熟悉 Flask 或其他 Web 框架</li>
<li>有 REST API 开发或微服务相关经验</li>
<li>了解容器和容器编排系统（Docker、Kubernetes、Rancher 等）</li>
</ul>
<p>加分项：</p>
<ul>
<li>了解 Angular/React/Vuejs（任一）</li>
<li>了解 MySQL、PostgreSQL 或其他 DBMS</li>
<li>了解或使用过 Jenkins</li>
<li>参与过开源项目</li>
<li>有网络、安全、虚拟化、云平台相关经验</li>
</ul>
<p>工作地点在上海/成都/台北。工作时间正常，不加班，不打卡，周末双休（965）。混合办公，每周可以最多五天居家办公（不限定时间，在正常工作和沟通的前提下，可以自己安排）。</p>
<p>联系方式：</p>
<ul>
<li>Email：<a href="mailto:grey.li@dell.com">grey.li@dell.com</a></li>
<li>微信：greyli_work</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/dell-python-jobs/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>《Flask 入门教程》第三版发布</title>
		<link>https://greyli.com/flask-tutorial-v3/</link>
		<comments>https://greyli.com/flask-tutorial-v3/#respond</comments>
		<pubDate>Sat, 16 Jul 2022 14:29:41 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[读书与写作]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Flask 入门教程]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=4416</guid>
		<description><![CDATA[最近手里堆积的事情越来越多，两本书的进度被日常工作挤压，于是非常想有一些小小的进展来缓解焦虑。刚好有读者来反馈 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>最近手里堆积的事情越来越多，两本书的进度被日常工作挤压，于是非常想有一些小小的进展来缓解焦虑。刚好有读者来反馈《<a href="https://helloflask.com/book/3/">Flask 入门教程</a>》不兼容最新版本 Flask 的问题，所以就花了一天时间来更新这个教程。</p>
<p><a href="https://greyli.com/flask-tutorial-v2-0-released/">发布上个版本</a>已经是 2019 年的事情了，这次针对 Flask 最新的 2.1.3 版本做了改写，同时不再兼容 Python 2.7 版本。优化了前面几章的一些内容，后面的章节需要改动的地方不多，就没有认真去更新。另外还顺便用 MkDocs 和 Netlify 把教程重新部署到了 <a href="https://tutorial.helloflask.com/">tutorial.helloflask.com</a> 上，后续会废弃掉 GitBook。</p>
<p>过去三年里，这本电子书大概给我带来了五百块的收入（主页上有一个自愿点击的「付费支持￥10」的按钮）。虽然不多，但是时不时收到到账提醒和鼓励的话还是很开心的。感谢每一位付款的读者！</p>
<p><a href="https://greyli.com/wp-content/uploads/2022/07/pay.jpg"><img class="aligncenter wp-image-4420 size-large" src="https://greyli.com/wp-content/uploads/2022/07/pay-534x1024.jpg" alt="" width="534" height="1024" srcset="https://greyli.com/wp-content/uploads/2022/07/pay-534x1024.jpg 534w, https://greyli.com/wp-content/uploads/2022/07/pay-78x150.jpg 78w, https://greyli.com/wp-content/uploads/2022/07/pay-157x300.jpg 157w, https://greyli.com/wp-content/uploads/2022/07/pay-624x1196.jpg 624w, https://greyli.com/wp-content/uploads/2022/07/pay.jpg 1170w" sizes="(max-width: 534px) 100vw, 534px" /></a></p>
<p>当然，给我带来更大成就感的是看到读者分享他/她<a href="https://discuss.helloflask.com/t/topic/64">通过阅读这个教程写的程序</a>，这是一种给别人带来成就感的成就感——元成就感。</p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/flask-tutorial-v3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如果你在 macOS 上无法访问 Flask 程序</title>
		<link>https://greyli.com/thank-you-apple/</link>
		<comments>https://greyli.com/thank-you-apple/#respond</comments>
		<pubDate>Sun, 03 Apr 2022 09:37:51 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Monterey]]></category>
		<category><![CDATA[ngrok]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=4298</guid>
		<description><![CDATA[如果你用 macOS 开发 Flask 时无法正常访问程序，或是使用 ngrok 等内网穿透工具时映射的公网地 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>如果你用 macOS 开发 Flask 时无法正常访问程序，或是使用 <a href="https://greyli.com/use-ngrok-to-expose-your-local-application/">ngrok</a> 等内网穿透工具时映射的公网地址无法访问，大概率是因为 macOS 新版本（Monterey）的变动导致。你会在页面上看到类似下面的错误信息：</p>
<pre>Access to 127.0.0.1 was denied.

You don't have authorization to view this page.

HTTP ERROR 403</pre>
<p>或是在执行 flask run 命令时看到类似下面的报错：</p>
<pre>OSError: [Errno 48] Address already in use</pre>
<p>首先确认你的 macOS 版本是不是 Monterey（左上角 Apple 图标 &#8211; About This Mac）或是之后的版本，如果不是那么问题应该和本文无关。</p>
<p>简单来说，新版本的 macOS 上 localhost 5000 端口被一个叫 AirPlay Receiver 的服务占用了。而 Flask 内置服务器默认就运行在 5000 端口，所以会造成端口冲突。当你通过将 host 设为 0.0.0.0 指定 Flask 的内置服务器对外可见，或是使用内网穿透工具时，会发现程序无法访问（有时未设置对外可见也会遇到这个问题）。</p>
<p>最简单的解决方法是关掉这个服务：</p>
<ul>
<li>系统设置（System Preferences） &gt; 分享（Sharing） &gt; AirPlay Receiver &gt; 取消勾选</li>
</ul>
<p>或是更改 Flask 开发服务器默认的端口（比如改成 8000）。在执行 flask run 命令时使用 -p/&#8211;port 选项可以自定义端口：</p>
<pre>$ flask run -p 8000  # 或 flask run --port 8000</pre>
<p>或是在执行 flask run 之前通过环境变量 FLASK_RUN_PORT 设置：</p>
<pre>$ export FLASK_RUN_PORT=8000 # macOS/Linux
&gt; set FLASK_RUN_PORT=8000 # Windows CMD
&gt; $env:FLASK_RUN_PORT=8000 # Powershell</pre>
<p>在 Werkzueg 2.1.0（2022/3/28 发布）版本，如果你执行 flask run &#8211;host=0.0.0.0 时检测到了端口被占用，会直接显示相关的错误提示：</p>
<pre>$ flask run --host=0.0.0.0
Address already in use
Port 5000 is in use by another program. Either identify and stop that program, or start the server with a different port.
On macOS, try disabling the 'AirPlay Receiver' service from System Preferences -&gt; Sharing.</pre>
<p>本文源于去年十一月发的<a href="https://twitter.com/greylihui/status/1455392110618857474">一条推文</a>，最近经常碰见有人遇到这个问题，所以转成这篇文章发出来。</p>
<p>画了一幅涂鸦，送给苹果公司：</p>
<p><a href="https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000.png"><img class="aligncenter size-full wp-image-4310" src="https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000.png" alt="" width="816" height="566" srcset="https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000.png 816w, https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000-150x104.png 150w, https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000-300x208.png 300w, https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000-624x433.png 624w" sizes="(max-width: 816px) 100vw, 816px" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/thank-you-apple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flask 工作机会</title>
		<link>https://greyli.com/flask-jobs/</link>
		<comments>https://greyli.com/flask-jobs/#respond</comments>
		<pubDate>Wed, 08 Dec 2021 08:40:43 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[工作机会]]></category>
		<category><![CDATA[找工作]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=4232</guid>
		<description><![CDATA[最近在找工作，发现了一些和 Flask 相关的工作机会。因为目前并没有一个收集 Flask 相关职位的平台，所 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>最近在<a href="https://greyli.com/job-search/">找工作</a>，发现了一些和 Flask 相关的工作机会。因为目前并没有一个收集 Flask 相关职位的平台，所以就在 GitHub 上创建了一个仓库来分享这些职位，希望可以帮到其他正在找工作的 Flask 用户：</p>
<ul>
<li><a href="https://github.com/greyli/flask-jobs">https://github.com/greyli/flask-jobs</a></li>
</ul>
<p>职位以 issue 的形式列出。目前列出来的几个都是和 Flask 关联非常大的职位，这里面有的我投递了申请（比如戴尔），有的收到了拒信（比如育碧），有的收到对方的面试邀请（比如 Dropbase）但并没有通过面试……所以这些职位都在开放中，如果你在找工作的话，尽管投递简历。同时也欢迎在投递之后回来分享面试进度/经历/经验。</p>
<p>如果你所在的公司正在招聘 Flask 相关的职位，或是你在未来发现某个公司发布新的 Flask 相关的职位，欢迎在这个仓库创建 issue 分享。创建 issue 时请遵循下面的格式要求：</p>
<ul>
<li>在标题注明「公司-职位-城市」，远程工作统一使用「Remote」。</li>
<li>把职位描述里的 requirements 部分贴到 issue 内，并在最后给出职位详情链接。</li>
<li>建议发布和 Flask 技术栈关联比较大的职位，不过 Python 相关的职位也欢迎。</li>
</ul>
<p>顺便说一句，有很多 Python 相关的工作都会要求掌握某一种 Python Web 框架，类似这样的描述：</p>
<ul>
<li>Good knowledge of web frameworks like Flask, Django, etc.</li>
</ul>
<p>即使对应职位实际不用 Flask 也不用担心，当你掌握了某一种框架，其他的框架学习起来会非常容易，因为大部分的概念都是相通的。而面试时也会根据你擅长的框架提问，所以尽管申请就好。</p>
<p>祝大家都能找到自己喜欢的工作。</p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/flask-jobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>开始写作《Flask Web 开发实战》第二版</title>
		<link>https://greyli.com/new-flask-book-plan/</link>
		<comments>https://greyli.com/new-flask-book-plan/#comments</comments>
		<pubDate>Sat, 30 Oct 2021 11:57:38 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[读书与写作]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Flask Web开发实战]]></category>
		<category><![CDATA[写作计划]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=4076</guid>
		<description><![CDATA[《Flask Web 开发实战》第二版已经开始写作，计划在今年完成这本书。那本《Python Web API  [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>《<a href="https://helloflask.com/book/4/">Flask Web 开发实战</a>》第二版已经开始写作，计划在今年完成这本书。那本《<a href="https://helloflask.com/book/2/">Python Web API 设计与开发</a>》一直拖着没写完，让我感觉很焦虑。因为拖得太久，HelloFlask 群聊里已经开始<a href="https://greyli.com/wp-content/uploads/2021/10/qq-chat.png" target="_blank" rel="noopener">谣传我转行送快递了</a> :D。</p>
<p>所以我想先把《Flask Web 开发实战》新版完成，这样这一年我至少完成了三个年度目标中的一个。「优化」是我擅长和喜欢做的事情，除了要用 Word 写之外，我很乐意给这本书写新版。</p>
<ul>
<li>主页：<a href="https://helloflask.com/book/4">https://helloflask.com/book/4</a></li>
<li>建议收集（或在文末留言）：<a href="https://discuss.helloflask.com/t/topic/838">https://discuss.helloflask.com/t/topic/838</a></li>
<li>写作进度和动态：<a href="https://discuss.helloflask.com/t/topic/837">https://discuss.helloflask.com/t/topic/837</a></li>
<li>合同截稿日期：<del>2021 年 12 月 31 日</del> 2022 年 1 月 31 日</li>
<li>预计出版日期：2022 年 <del>2～3 月</del> 6~7 月</li>
</ul>
<h2>内容变动</h2>
<p>在各处收集了很多读者反馈和建议，综合我自己的规划，第二版主要有这些大的变动：</p>
<ul>
<li>不再兼容 Python 2.7，基于 Python 3.x、Flask 2.x。</li>
<li>把大部分知识点集中到第一部分，让第二部分的示例程序内容更精简。</li>
<li>第 1 章使用 pip+venv（+pip-tools） 或 PDM 替代 Pipenv，增加更多对 PyCharm 的介绍。</li>
<li>第 6 章使用 Flask-Mailman 替代 Flask-Mail（同时引入介绍一些新的扩展，比如 Flask-Admin）。</li>
<li>删除第 9、10、11 章（删除后 3 个实战项目），仅保留 Sayhello 和 Bluelog，删减项目的部分功能会合并到这两个项目。</li>
<li>第 10 章删除实战项目，只保留 Web API 开发部分，会新引入 marshmallow 和 APIFlask。</li>
<li>第 12 章添加异步任务相关内容。</li>
<li>第 14 章添加 Docker 相关内容。</li>
<li>删除第 15 章（Flask 扩展开发）。</li>
<li>删掉一些在国内访问有问题的服务介绍，比如 SendGrid（第 6 章）、Heroku（第 14 章）、Twitter 第三方登录（第 11 章）。</li>
</ul>
<p>大部分内容变动是在做删减，第一版 704 页，第二版内容会删减到 450 页左右。</p>
<h2>代码片段</h2>
<p>第一部分每一章都有一个示例程序，读者需要切换到每一个子文件夹运行，如果同时自己编写练习代码的话，很容易产生混乱。所以新版的考虑是，第一部分的示例程序不再给出可运行的示例文件（至少不在书里介绍），而是把所有的代码片段放到 <a href="https://docs.helloflask.com/">HelloFlask 文档</a>，以代码片段的形式组织。读者需要的话可以自己复制代码到本地运行。作为示例，第一章的代码片段可以在这里看到：<a href="https://docs.helloflask.com/book/4/snippets/c1/">https://docs.helloflask.com/book/4/snippets/c1/</a>。因为前六章的代码片段变化不大，所以第一版的读者也可以使用这些文档。</p>
<p>P.S. HelloFlask 文档（<a href="https://docs.helloflask.com">https://docs.helloflask.com</a>）是我最近刚创建的一个文档集合。所有和书相关的内容都会放到这里，比如勘误、代码片段、衍生文章等。后续也会在这里写一些扩展快速入门介绍、Flask 基础知识等 Flask 相关的东西。</p>
<h2>书名</h2>
<p>第二版因为有独立的书号，所以可以改书名。责编老师认为原书名就很好，换书名会浪费掉第一本书建立的品牌。我也基本同意这个观点。目前的考虑是主书名不变，出于营销的考虑，副书名或许可以加一个「Python」关键字，比如改成「Python Web 开发入门、进阶与原理解析」。</p>
<h2>封面</h2>
<p>目前这本书<a href="https://helloflask.com/book/4/">主页</a>上的封面不是正式封面（我用画图软件在初版封面上随手涂了两笔 &gt;_&lt;）。目前的想法是把封面标题颜色换成深红色，然后换一个封面图案，不过暂时还没想好换成什么。</p>
<h2>措辞</h2>
<p>第一版是用 Word 写的，排版很痛苦，毕竟要在 Word 里面排版代码。第二版也要继续用 Word 写，而且更加痛苦，因为第二版的书稿是编辑老师用工具从 PDF 文件转制成 Word 的，大部分格式都变得很混乱。希望这是我最后一次用 Word 来写技术书。</p>
<p>对于第一版，我交的终稿和最终成书有一些内容的变化，编辑老师会修正错别字和一些病句。但是后面也发现有一些句子修改得并不合理，导致句子原意产生了变化。这次我会在出版前过一遍校正后的书稿，确保不会再出现这样的情况。</p>
<p>另外，编辑老师还会替换一些词汇用法，比如把「我」替换为「笔者」，这个笔者勉强能接受，但是笔者最不能接受的就是要把所有的「点击」改成「单击」。单击一个链接？这太奇怪了。今年和编辑老师再次沟通了这件事，事情终于有了变化，书中的「点击」在这一版不用再死板的按照出版社的规定修改为「单击」。新的读者不会被指导在网页上单击一个链接了。</p>
<h2>周边开源项目</h2>
<p>我的很多开源项目的开发都是写作驱动的，上一本书驱动我开发了那几个 Flask 示例程序和扩展，这一次同样会有一些开发计划：</p>
<ul>
<li>APIFlask：补齐所有文档，发布 1.0 版本。</li>
<li>Bootstrap-Flask：添加 Bootstrap 5 支持。</li>
<li>Flask-CKEditor：添加 CKEditor 5 支持，同时集成新版本内置的 Markdown 支持。</li>
<li>Flask-WTF：添加多文件上传验证支持。</li>
<li>Sayhello：添加分页、多语言、Markdown 支持等功能（总之就是尽可能把删减的示例程序里比较有意思的功能合并到这里）。</li>
<li>Bluelog：把 Albumy 的除了图片相关的功能合并过来，会换一个名字（暂定 WeBlog），作为一个社交博客。</li>
</ul>
<p>如果你对这本书的新版有其他建议和想法，欢迎提出。这两本新书相关的动态会发到 <a href="https://twitter.com/helloflask">Twitter @helloflask</a> 和我的<a href="https://greyli.com/files/qrcode_gh.jpg">公众号</a>，欢迎关注。</p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/new-flask-book-plan/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>2021 年 Flask 用户调查报告</title>
		<link>https://greyli.com/flask-report-2021/</link>
		<comments>https://greyli.com/flask-report-2021/#comments</comments>
		<pubDate>Thu, 07 Oct 2021 10:06:23 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计划与总结]]></category>
		<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[调查报告]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=3985</guid>
		<description><![CDATA[七月份创建了一个 Flask 用户调查问卷，到目前为止一共收集到 104 份提交，感谢各位的参与！这篇文章会对 [&#8230;]]]></description>
				<content:encoded><![CDATA[
<p>七月份创建了一个 <a href="https://jinshuju.net/f/UY6Rd8">Flask 用户调查问卷</a>，到目前为止一共收集到 104 份提交，感谢各位的参与！这篇文章会对问卷收集结果做一个总结，作为一份（非官方的）2021 年（104 位中国）Flask 用户调查报告。</p>
<p>如果你想自己看原始数据，下面是剔除了隐私信息的问卷提交数据文件（CSV 格式）：</p>
<p><a href="https://helloflask.com/downloads/flask_report_2021.csv">https://helloflask.com/downloads/flask_report_2021.csv</a></p>
<figure><a href="https://greyli.com/wp-content/uploads/2021/10/result.png"><img class="aligncenter size-large wp-image-3987" src="https://greyli.com/wp-content/uploads/2021/10/result-1024x300.png" alt="" width="625" height="183" srcset="https://greyli.com/wp-content/uploads/2021/10/result-1024x300.png 1024w, https://greyli.com/wp-content/uploads/2021/10/result-150x44.png 150w, https://greyli.com/wp-content/uploads/2021/10/result-300x88.png 300w, https://greyli.com/wp-content/uploads/2021/10/result-624x183.png 624w" sizes="(max-width: 625px) 100vw, 625px" /></a></figure>
<p>如果你现在还想参与的话，完全来得及，下面是问卷的地址：</p>
<p><a href="https://jinshuju.net/f/UY6Rd8">https://jinshuju.net/f/UY6Rd8</a></p>
<h2>你在工作中使用 Flask 吗？</h2>
<p>在提交的 104 份问卷里，接近一半的人在工作中使用 Flask，详情如下：</p>
<figure><a href="https://greyli.com/wp-content/uploads/2021/10/use-flask.png"><img class="aligncenter size-large wp-image-3989" src="https://greyli.com/wp-content/uploads/2021/10/use-flask-1024x375.png" alt="你在工作中使用 Flask 吗？" width="625" height="229" srcset="https://greyli.com/wp-content/uploads/2021/10/use-flask-1024x375.png 1024w, https://greyli.com/wp-content/uploads/2021/10/use-flask-150x55.png 150w, https://greyli.com/wp-content/uploads/2021/10/use-flask-300x110.png 300w, https://greyli.com/wp-content/uploads/2021/10/use-flask-624x229.png 624w" sizes="(max-width: 625px) 100vw, 625px" /></a></figure>
<p>算上我，还没找到工作的人竟然只有 5 个（《震惊！某份民间调查显示 Flask 用户无业率仅有 4.8 %！》:P）。</p>
<h2>Flask 中文文档标语翻译</h2>
<p>前段时间发起了 <a href="https://greyli.com/flask-docs-zh/">Flask 中文文档翻译</a>，目前正在龟速进行中，欢迎英语比较好的同学参与（翻译或审核<a href="https://github.com/flaskcwg/flask-docs-zh/pulls">已经提交的 PR</a>）。<a href="https://flask-zh.readthedocs.io/">文档首页</a>的 logo 图片里有一句标语——「web development, one drop at a time」，我临时翻译为「Web 开发，一次一滴」。在 <a href="https://github.com/flaskcwg/flask-docs-zh/discussions/37">GitHub 仓库的讨论</a>里，大家给出了更多更好的备选项。根据这次问卷投票的结果，「Web 开发，起于点滴」排在第一位（由 HelloFlask QQ 群里一位翻译专业的同学翻译），详情如下：</p>
<figure><a href="https://greyli.com/wp-content/uploads/2021/10/slogan.png"><img class="aligncenter size-large wp-image-3988" src="https://greyli.com/wp-content/uploads/2021/10/slogan-1024x543.png" alt="Flask 标语翻译" width="625" height="331" srcset="https://greyli.com/wp-content/uploads/2021/10/slogan-1024x543.png 1024w, https://greyli.com/wp-content/uploads/2021/10/slogan-150x80.png 150w, https://greyli.com/wp-content/uploads/2021/10/slogan-300x159.png 300w, https://greyli.com/wp-content/uploads/2021/10/slogan-624x331.png 624w" sizes="(max-width: 625px) 100vw, 625px" /></a></figure>
<p>更保险的选择是「不作翻译」，在投票中排在第二位，最终我会考虑从这两者之间选择。另外，如果翻译的话，如果翻译的话，「Web」会考虑按照英文近年的惯用趋势而使用全小写（你觉得呢？​）。</p>
<p>P.S. 在 GitHub 上的投票结果里，<a href="https://github.com/abersheeran">@abersheeran</a> 翻译的「Web 开发，起自微毫」和「任取随用的 Web 框架」<a href="https://github.com/flaskcwg/flask-docs-zh/discussions/37#discussioncomment-795727">票数最高</a>。</p>
<h2>对 Flask 的新功能请求 &amp; 改进建议</h2>
<p>剩下几个问题不方便详细统计和展示，我粗略看了一遍，整理出了关注度最高的几件事。我一一在下面评注了我的想法以及相应的动态。</p>
<h3>添加更多 Web API 开发支持</h3>
<blockquote>
<p>开发接口时自动生成swagger</p>
<p>对 Web API 很友好的支持</p>
<p>加入pydantic用于类型检查</p>
</blockquote>
<p>Flask 作为一个通用型框架，不会添加太多关于 Web API 这种细分方向的支持。除了手动集成这些功能/工具，你可以考虑选择基于 Flask 而且集成了这些功能的二次框架，比如 <a href="https://apiflask.com/">APIFlask</a>、<a href="https://flask-smorest.readthedocs.io/en/latest/">flask-smorest</a>、<a href="https://0b01001001.github.io/spectree/">Spectree</a> 等。</p>
<h3>添加基于 ASGI 的异步实现</h3>
<blockquote>
<p>加强对异步的支持</p>
<p>异步支持的不是很成熟</p>
<p>可能是速度吧，据说现在很多新框架都比Flask快，要淘汰Flask云云</p>
</blockquote>
<p>Flask 目前的<a href="https://flask.palletsprojects.com/en/2.0.x/async-await/">异步支持</a>已经能够满足大部分使用场景。据我所知，基于 ASGI 的异步支持短期内不会实现。</p>
<p>而对于鼓吹性能的文章可以不用太在意：异步和高性能不直接划等号。技术选型不会只考量性能。benchmark 未必客观和能够反映真实情况。如果对异步有强需求，可以考虑用和 Flask 相同 API 的 <a href="https://pgjones.gitlab.io/quart/">Quart</a>（一个 Flask 的 ASGI 异步实现），或是换用其他异步框架。</p>
<h3>官方维护的扩展列表</h3>
<blockquote>
<p>一个针对新手的 flask extension 的指南</p>
<p>由Pallets Projects开发团队的成员或者flask官方统一所有第三方插件的开发与发布，目前太乱了，有些都快停更十年了，还占用名字。</p>
<p>各种插件扩展选择太多，但是又质量层次不齐，此外很多个人维护的扩展可能由于开发者精力有限在后期会出现项目生命周期的问题，如：flask_restful，需要官方对常用扩展维护一套比较简洁的扩展。当然这样的话可能又走上了Django的老路，可能作者正在计划的“Flask扩展收容计划”是一个不错的选择，起码可以管理起来。但是脱离原作者维护的项目后期发展如何又成为另一个话题。比如需要对插件进行遴选，另外需要对该计划由官方进行宣传等</p>
</blockquote>
<p>这件事我之前有计划在做，前段时间注册了 flaskextensions.org，想用来做一个这样的扩展推荐列表。在 Pallets 会议上沟通之后，决定交给 Pallets 官方来做，所以把域名转给了 Pallets 团队，后续会做一个这样的列表出来：列出来推荐的 Flask 扩展，并给出失去维护扩展的替代品。</p>
<p>另外 Pallets 在 GitHub 创建了一个 <a href="https://github.com/pallets-eco">pallets-eco 组织</a>，用来收纳失去维护（维护者不想再继续维护）的流行 Flask 扩展，让它们保持健康的维护状态（由社区维护）。目前有两个扩展进入这个组织，分别是 <a href="https://github.com/pallets-eco/flask-caching">Flask-Caching</a> 和 <a href="https://github.com/pallets-eco/flask-openid">Flask-OpenID</a>。</p>
<h3>脚手架工具和大型项目组织</h3>
<blockquote>
<p>统一并明确开发的工程化流程，包括项目应该新建那些文件夹等。</p>
<p>缺少小白懒人快速一键生成集成框架（webadmin, mysql）</p>
<p>引入蓝图想搞玩大型项目，可大型项目又需要自己组织好项目结构，需要一个对flask很熟悉的人做这事 还不如用django。官方推一个脚手架生成项目模板吧像vue-cli一样 包括是否使用orm等插件，不然还不如django搭建起来快。。</p>
</blockquote>
<p>作为一个微框架，Flask 的初衷是不限定项目文件组织形式，所以官方不太可能会出一个脚手架工具或是项目组织指南。在工厂函数和蓝本这两个概念的基础上，你可以自由组织你的项目。另一方面，市面上已经有很多项目模板或是脚手架工具（比如 <a href="https://github.com/cookiecutter-flask/cookiecutter-flask">cookiecutter-flask</a>），也有很多介绍 Flask 项目组织的文章，你可以根据这些工具和文章制定自己的规则，然后为你的组织或团队确定一个项目组织规范或是写一个脚手架工具，或许这才是 Flask 的「正确食用方式」。如果你更需要一个固定的项目组织模式，那么 Django 或许是更好的选择。</p>
<p>我也有计划写一个更简单的脚手架工具（对我来说市面上那些都太复杂，引入了太多扩展和工具），同时给出一份 Flask 项目组织建议，这件事也许会在写《<a href="https://helloflask.com/book/1/">Flask Web 开发实战</a>》第二版的过程里完成。</p>
<h3>Bootstrap-Flask 的 Bootstrap 5 支持</h3>
<blockquote>
<p>Bootstrap-Flask 希望可以早点同步 Bootstrap5 的相关内容。因为Bootswatch的最新版本有我想要使用的组件，但是Bootstrap-Flask只支持到Bootstrap4，所以有些宏无法正常显示，比如render_form等。还有希望Bootstrap-Flask的wiki能够更加的完善和细节，我会持续关注，大佬辛苦</p>
</blockquote>
<p>提交的问卷里有一条说到这件事，此前在 <a href="https://twitter.com/jugmac00/status/1415369405249335303">Twitter</a> 和 <a href="https://github.com/greyli/bootstrap-flask/issues/120">GitHub</a> 上也有人提到，所以也放到一起说一下。我已经在做这件事了，基本的 Bootstrap 5 支持已在 <a href="https://github.com/greyli/bootstrap-flask/pull/161">#161</a> 完成，完整的实现会在下个月完成（详见 <a href="https://github.com/greyli/bootstrap-flask/issues/162">#162</a>），届时会随 2.0 版本发布。</p>
<p>除了这些，提交的问卷里还有很多其他的建议和问题，我没法一一回应。有时间我会看看问题里提出的问题有哪些我可以试着解决和改善。同时也欢迎你一起尝试解决这些提出的问题，感兴趣的话，去翻翻上面给出的问卷数据吧。</p>
<h2>总结</h2>
<p>总体来看，Flask 社区在朝着好的方向发展，希望明年这里提到的大多数计划都会有着落。一起加油！</p>
<p>P.S. <a href="https://flaskcon.com/">FlaskCon 2021</a> 会在今年 12 月举办，如果你有 Flask 相关的内容想分享，欢迎报名（英文，预录制演讲）。</p>
<hr />
<p>相关链接：</p>
<ul>
<li><a href="https://www.v2ex.com/t/806256">本文在 V2EX 的讨论</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/flask-report-2021/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>欢迎填写 Flask 用户调查问卷</title>
		<link>https://greyli.com/flask-user-survey/</link>
		<comments>https://greyli.com/flask-user-survey/#respond</comments>
		<pubDate>Tue, 20 Jul 2021 07:07:21 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[Flask]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=3928</guid>
		<description><![CDATA[以参加捕蛇者说播客录制 Ep 30 为契机，创建了一个 Flask 用户调查问卷，用来收集 Flask 用户的 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>以参加<a href="https://greyli.com/flask-talk/">捕蛇者说播客录制 Ep 30</a> 为契机，创建了一个 Flask 用户调查问卷，用来收集 Flask 用户的反馈和建议。尽管这个问卷是由我个人而不是 Flask 官方（Pallets）发起（不过 Flask 官方也在计划着做一个调查问卷），但是我会把收集到的信息反馈到 Flask 开发团队进行讨论。因此，你的建议的确有可能让 Flask 变得更好。</p>
<p>不管你对于 Flask 是有明确的变动建议，还是只是对某个功能不甚满意，都可以把你的想法写下来。谢谢！</p>
<p>问卷地址：<span spellcheck="false"><a href="https://jinshuju.net/f/UY6Rd8">https://jinshuju.net/f/UY6Rd8</a></span></p>
<hr />
<p>同时借这个问卷送出四本《Flask Web 开发实战》，填写问卷即可参与。每份问卷会有一个提交序号，中奖序号为 27、36、41、58。预计抽奖会在 7 月 22 号完成，届时抽奖结果会更新到这篇文章。</p>
<p>7 月 21 日更新，抽奖结果已产生：</p>
<p><a href="https://greyli.com/wp-content/uploads/2021/07/result.png"><img class="aligncenter size-large wp-image-3938" src="https://greyli.com/wp-content/uploads/2021/07/result-340x1024.png" alt="" width="340" height="1024" srcset="https://greyli.com/wp-content/uploads/2021/07/result-340x1024.png 340w, https://greyli.com/wp-content/uploads/2021/07/result-50x150.png 50w, https://greyli.com/wp-content/uploads/2021/07/result-100x300.png 100w, https://greyli.com/wp-content/uploads/2021/07/result-624x1878.png 624w, https://greyli.com/wp-content/uploads/2021/07/result.png 780w" sizes="(max-width: 340px) 100vw, 340px" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/flask-user-survey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
