Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Miguel Grinberg

Rating No ratings yet

Take full creative control of your web applications with Flask, the Python-based microframework. With the second edition of this hands-on book, you’ll learn Flask from the ground up by developing a complete, real-world application created by author Miguel Grinberg. This refreshed edition accounts for important technology changes that have occurred in the past three years. Explore the framework’s core functionality, and learn how to extend applications with advanced web techniques such as database migrations and an application programming interface. The first part of each chapter provides you with reference and background for the topic in question, while the second part guides you through a hands-on implementation. If you have Python experience, you’re ready to take advantage of the creative freedom Flask provides. Three sections include: • A thorough introduction to Flask: explore web application development basics with Flask and an application structure appropriate for medium and large applications • Building Flasky: learn how to build an open source blogging application step-by-step by reusing templates, paginating item lists, and working with rich text • Going the last mile: dive into unit testing strategies, performance analysis techniques, and deployment options for your Flask application

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on guide that teaches Flask by building one real blogging application from first route to production deployment. Best for Python developers who want practical web skills without wading through a heavyweight framework. 【Book Arc】 - **Opening (~0%–10%)**: Sets up the development environment, introduces Flask's request-response cycle, routing, and the built-in development server, establishing the smallest working app. - **Early (~10%–35%)**: Covers the presentation layer — Jinja2 templates, static files, web forms with Flask-WTF, sessions, and message flashing — so the app can accept and echo user input. - **Middle (~35%–55%)**: Moves into data: SQL vs. NoSQL trade-offs, Flask-SQLAlchemy models and relationships, query filters, and Alembic/Flask-Migrate schema migrations. - **Late (~55%–80%)**: Builds out the Flasky blogging app — user authentication, roles/permissions, post creation with rich text, pagination, and follower relationships (excerpts thin here). - **Ending (~80%–100%)**: The "last mile" — unit testing strategies, performance analysis, and deployment options including containers and orchestration (excerpts thin here). 【Key Takeaways】 - **Flask is a microframework, not a scaffold** (Opening): it gives you routing and templates, then leaves architecture choices to you — the book supplies an application structure suited to medium and large projects. - **Every chapter pairs reference with implementation** (Early): background first, then hands-on code, so concepts land through building rather than reading alone. - **Responses are more than strings** (Early): view functions can return status codes, header dictionaries, or full response objects via `make_response()`, which is how cookies and custom headers get set. - **Jinja2 templates are a real language** (Early): variables, filters, conditionals, and inheritance let you keep logic out of Python while still rendering dynamic pages. - **Forms need validation, not just HTML** (Early): Flask-WTF wraps WTForms to remove repetitive form generation and validation work, and sessions plus `flash()` carry state and feedback across requests. - **Database choice is a design decision** (Middle): SQL databases prioritize ACID consistency; NoSQL trades some of that for speed via denormalization — for small to medium apps the two are practically equivalent. - **Migrations are version control for your schema** (Middle): Alembic scripts have `upgrade()` and `downgrade()`; auto-generated migrations must be reviewed because renames can be misread as drop-and-add, risking data loss. - **Shipping is part of development** (Ending): testing, performance analysis, and deployment (including containers) are treated as first-class steps, not afterthoughts. 【Reading Tips】 - **Deep-read the early chapters** on routing, responses, and templates — later chapters assume this fluency and move faster. - **Skim the SQL vs. NoSQL discussion** if you already know your database; the actionable part is the SQLAlchemy modeling and migration workflow. - **Follow along with the Flasky repository** using the `git checkout` tags mentioned in the text; comparing revisions is far more instructive than reading finished code. - **Treat migration scripts as code to review**, not generate-and-forget — the book explicitly warns about automatic migration inaccuracies. - **Don't skip the last mile** even if deployment feels distant; testing and containerization are where tutorials usually stop and real projects begin. 【Coverage Limits】 The excerpts are dense on the opening through middle chapters (setup, templates, forms, database, migrations) but thin on authentication, the full Flasky build-out, testing, and deployment. Claims about the late and ending sections are inferred from the book's stated three-part structure rather than detailed excerpt content.
Page 12
Compose 265 Cleaning Up Old Containers and Images 269 Using Docker in Production 270 Traditional Deployments 270 Server Setup 271 Importing Environment Varia...
View in text
Excerpt 2
template() provided by Flask integrates the Jinja2 template engine with the application. This function takes the filename of the template as its first argume...
View in text
Excerpt 3
ve the format {% if condition %}...{% else %}...{% endif %}. If the condition evaluates to True, then what appears between the if and else directives is adde...
View in text
Excerpt 4
les in a database migration repository must always be added to version control along with the rest of the application. Creating a Migration Script In Alembic...
View in text
Excerpt 5
ed function is used as the command name, and the function’s docstring is displayed in the help messages. The implementation of the test() func‐ tion invokes...
View in text
Excerpt 6
set to True for only one role and False for all the others. The role marked as default will be the one assigned to new users upon registration. Since the app...
View in text
Excerpt 7
=url, hash=hash, size=size, default=default, rating=rating) To avoid duplicating the logic to compute the gravatar hash, a new method, gravatar_hash(), is ad...
View in text
Excerpt 8
y to use through the foreign_keys optional argument. The db.backref() arguments in these relation‐ ships
View in text
Tags
AI categories
PythonWeb TechnologyBackend
ISBN: 1491991739
Publisher: O'Reilly Media
Publish Year: 2018
Language: English
Pages: 316
File Format: PDF
File Size: 5.4 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…