Flask Web Development: Developing Web Applications with Python, 2nd Edition cover

Flask Web Development: Developing Web Applications with Python, 2nd Edition

Rating 4.3
Word count
220K words
Chapters
40
Series
Turing Programming Series
ISBN
9787115489456

Tags

Summary

This is one of the most widely circulated Chinese introductory textbooks on Flask development, written by Miguel Grinberg, a longtime Python web developer, translated by An Dao, and part of the Turing Programming Series. The book has 18 chapters in three parts. Part One starts from the most basic environment setup, introducing virtual environments and pip, the basic structure of an application, routing and view functions, the request-response cycle, request hooks and contexts, and then covers Jinja2 templates, Flask-Bootstrap, Flask-Moment, web forms and WTForms, SQLAlchemy database modeling and migrations, sending email with Flask-Mail, and organizing large applications with application factory functions and blueprints. Part Two is a hands-on project running through the whole book: building a social blogging application called Flasky from scratch, adding chapter by chapter user authentication, role permissions, user profiles and avatars, blog posts with pagination and Markdown rich text, follower relationships, comment management, and finally implementing a REST-style application programming interface with Flask-HTTPAuth and JSON serialization. Part Three is aimed at going live, covering testing and code coverage, Selenium end-to-end testing, performance analysis and slow-query logging, deployment on Heroku and Docker containers as well as traditional servers, and resources for finding extensions and joining the community. The second edition is fully revised for Python 3.6, concise in length, and focuses on linking framework features into a complete, practical development chain, suitable as a mainline text for systematically learning Flask.

Editor's review

很多Python学习者的困境是:语法会了,却不知道一个真实网站是怎么一步步长出来的。这本书的价值正在于此——它不讲零散的知识点,而是用“做一个小型社交博客”这条主线,把Flask从路由、模板、表单、数据库到用户认证、权限、评论、API全部串起来,读完你能得到一个自己写完、能跑起来、能上线的完整项目。 本书结构清晰是最大优点:第一部分打地基,每一章只引入一类必要概念和对应扩展;第二部分边做边把前面分散的知识缝合进同一个工程,让你理解工厂函数和蓝本存在的理由;第三部分专门讲测试、性能与部署,这部分恰恰是多数入门书缺失的“最后一百米”。 第2版针对Python 3.6全面修订,篇幅控制在两百余页,不写废话,代码示例密度高。需要提醒的是:技术类书籍的版本时效性天然有限,书中不少扩展库的配置方式在新版本中已有变化,因此它更适合当作“理解Flask工程化开发思路”的教材,而不是逐个复制代码的速查手册。配合官方文档与最新版本实践一起读,收益最大。

Who it's for

A good fit for

  • 熟悉Python基础语法、想系统入门Web后端开发的程序员或学生
  • 已经会用Django或其他框架,想快速了解Flask轻量级开发模式的开发者
  • 需要独立完成一个带用户系统、评论和API的完整小项目的自学者
  • 正在做毕业设计或课程设计、缺少实战项目经验的高年级本科生与研究生

Not a good fit for

  • 完全没有编程基础、尚未学过Python基本语法与面向对象概念的读者
  • 只想查找Flask最新版本API速查手册、不打算按章节动手实践的人
  • 主要做前端或数据科学、短期内不需要搭建Web服务端的读者

Reading tips

  1. 务必边读边敲代码,第一部分每章结束后亲手复现示例,否则到第二部分会跟不上项目节奏。
  2. 先读第2章和第7章,理解应用工厂函数与蓝本的用意,再回头逐章补细节,能明显降低理解难度。
  3. 书中的扩展版本较旧,动手时对照各扩展官网最新文档调整配置,遇到报错优先查阅官方变更说明。
  4. 读完后不要停在Flasky项目上,自己重写一个主题不同的小应用(如书籍收藏或待办清单),把知识迁移验证一遍。

About the publisher

Posts & Telecom Press China · Founded in 1953

Posts & Telecom Press is known for its strengths in science and technology, computing, and information and communications titles, and has extended its publishing into photography, art, software learning, and inspirational growth, giving it a fairly diverse range. Its catalog includes computing and communications works such as Refactoring and Patterns (Revised Edition) and Huawei Switch Learning Guide (Second Edition), alongside bilingual collector's editions such as The Little Prince (Chinese-English-French illustrated collector's edition), The Great Gatsby, and Three Days to See. Beijing Ten Years: 1980-1990 and Ghost Blade: WLOP Personal Illustration Collection reflect its presence in photography and art. Its authors include Antoine de Saint-Exupéry, Helen Keller, Joshua Kerievsky, Wang Da, Zhang Zhaozeng, and WLOP.

Contents

  1. Preface
  2. Part One Introduction to Flask
  3. Chapter 1 Installation
  4. 1.1 Creating the Application Directory
  5. 1.2 Virtual Environments
  6. 1.3 Creating a Virtual Environment in Python 3
  7. 1.4 Creating a Virtual Environment in Python 2
  8. 1.5 Using Virtual Environments
  9. 1.6 Installing Python Packages with pip
  10. Chapter 2 Basic Structure of an Application
  11. 2.1 Initialization
  12. 2.2 Routes and View Functions
  13. 2.3 A Complete Application
  14. 2.4 The Web Development Server
  15. 2.5 Dynamic Routes
  16. 2.6 Debug Mode
  17. 2.7 Command-Line Options
  18. 2.8 The Request-Response Cycle
  19. 2.9 Flask Extensions
  20. Chapter 3 Templates
  21. 3.1 The Jinja2 Template Engine
  22. 3.2 Integrating Bootstrap with Flask-Bootstrap
  23. 3.3 Custom Error Pages
  24. 3.4 Links
  25. 3.5 Static Files
  26. 3.6 Localizing Dates and Times with Flask-Moment
  27. Chapter 4 Web Forms
  28. 4.1 Configuration
  29. 4.2 Form Classes
  30. 4.3 Rendering Forms as HTML
  31. 4.4 Handling Forms in View Functions
  32. 4.5 Redirects and User Sessions
  33. 4.6 Flash Messages
  34. Chapter 5 Databases
  35. 5.1 SQL Databases
  36. 5.2 NoSQL Databases
  37. 5.3 SQL or NoSQL
  38. 5.4 Python Database Frameworks
  39. 5.5 Managing Databases with Flask-SQLAlchemy
  40. 5.6 Defining Models

FAQ

这本书适合完全没有编程基础的人吗?
不太适合。书中假设读者已经掌握Python的基本语法、函数、类和模块的用法,只简要提及虚拟环境与pip。若尚未写过Python程序,建议先学一门Python入门课,再回来读本书,否则前两章就会卡住。
第1版和第2版有什么区别,该买哪一本?
第2版针对Python 3.6全面修订了代码与依赖,并新增了Docker容器部署等内容,结构也做了调整;第1版对应Python 2时代的写法。如今应选第2版,Python 2相关内容已无实际意义。
书里的示例代码在新版本Python和扩展库上还能跑吗?
基本思路仍然成立,但部分扩展的导入方式、配置名和命令已发生变化,直接复制可能报错。建议以书中流程为骨架,具体参数查阅当前版本的官方文档,遇到不兼容处自行调整。
读完后能独立开发一个上线的Web项目吗?
可以完成结构完整的项目骨架。书中涵盖了认证、权限、数据库迁移、API、测试与部署等关键环节,但真实项目还需要补充缓存、异步任务、安全加固与运维监控等知识,本书是起点而非终点。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

More by the same author

Top rated in the same category