Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Takatomo Honda

Rating No ratings yet

Flask is a Python web application framework. Flask makes it easy to create small applications and even extend them to larger applications. In this book, you'll learn how to create a new blog application from scratch. It is organized so that you can learn about the kinds of technology necessary for developing web applications in each chapter while you are building them. By reading through this book, you will naturally learn the basics of Flask: from developing the MTV framework, which is the concept of the Flask framework, implementing authentication through the creation of login functions, creating templates using Bootstrap or Jinja 2, and working with databases. Table of Contents: 1. Introduction 2. Completed image of the blog application 3. Installing Python 4. Installing pip 5. Try running the application in a single file 6. Installing Pipenv 7. Create the startup file 8. Creating a config file - Allowing you to work with settings together 9. Understanding the Flask Framework - MTV Framework 10. Creating Templates - Templates in the MTV Framework 11. Introducing Bootstrap - Refine Your Design 12. Create a login form - Implement a form 13. Create a View - View in the MTV framework 14. Creating a base layout template 15. Working with sessions - Enabling secure logins through authentication 16. Add flash - Display a message to the user 17. url_for - Automatically Create Links 18. Work with databases 19. Model - Model in the MTV framework 20. Create scripts - make certain actions common 21. Learn about CRUD 22. Create Blog Posts - Create in CRUD 23. Create a Blog List Feature - Read in CRUD 24. Creating Blog Details - Read in CRUD 25. Create Blog Editing - Update in CRUD 26. Create a Blog Post Delete Feature - Delete in CRUD 27. Add static files - Allowing you to work with images and stylesheets 28. Create a decorator for login authentication 29. Splitting an Application with Blueprint 30. Writing Unit Tests 31. Measuring and Reporting Test Coverage 32. Final applica

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 beginner's guide that walks you through building a complete blog application in Flask, teaching web development fundamentals through doing rather than abstract theory. Best suited for Python learners who want to understand how a real web app fits together from routing to database to deployment-ready structure. 【Book Arc】 - **Opening (~0%–15%)**: Environment setup and first steps — installing Python, pip, and Pipenv, running a single-file Flask app, then splitting into a startup file and config file to establish project structure. - **Early (~15%–35%)**: Core Flask concepts — the MTV (Model-Template-View) framework, routing, Jinja2 templates, Bootstrap for styling, login forms, sessions for authentication, flash messages, and `url_for` for link generation. - **Middle (~35%–55%)**: Database integration and the Model layer — defining models as Python classes, creating database scripts, and understanding how Flask connects to persistent storage through an ORM. - **Late (~55%–85%)**: Full CRUD implementation — building blog post creation, listing, detail viewing, editing, and deletion features, plus static file handling for images and stylesheets. - **Ending (~85%–100%)**: Production-quality practices — login authentication decorators, Blueprint for splitting large applications into modules, unit testing, and measuring test coverage. 【Key Takeaways】 - **MTV is the mental model for Flask** (Early): Model handles data, Template handles presentation, View handles request logic — understanding this separation makes every subsequent chapter easier to follow. - **Pipenv solves environment isolation** (Opening): Each project gets its own dependency environment, preventing version conflicts across multiple Python projects on the same machine. - **Configuration belongs in a dedicated file** (Early): Moving settings like `DEBUG` and credentials into `config.py` keeps the application body clean and makes environment-specific changes manageable. - **Template inheritance eliminates duplication** (Early): A base `layout.html` with `{% block body %}` lets every page share navigation, styles, and structure while overriding only what differs. - **Sessions enable stateful authentication** (Early): Flask's session object tracks login state across requests, and `flash` provides user feedback for success and failure cases. - **CRUD is the backbone of most web apps** (Late): Creating, reading, updating, and deleting blog posts maps directly to the operations nearly every data-driven application needs. - **Blueprints scale Flask beyond small apps** (Ending): Splitting views into modules keeps the codebase navigable as features grow, directly addressing Flask's "microframework" limitation. - **Testing and coverage measurement close the loop** (Ending): Unit tests verify behavior, and coverage reporting reveals untested paths — essential habits for maintainable code. 【Reading Tips】 - **Deep-read the MTV chapter (ch. 9)**: Everything afterward assumes you understand how requests flow through View → Model → Template. Skim the installation chapters if your environment is already set up. - **Type every code block yourself**: This is a build-along book. Copy-pasting skips the debugging moments where real learning happens — especially around config errors and template path issues. - **Pause at the CRUD chapters to plan your own variation**: Once you've built the blog, try adding a comment feature or tag system using the same patterns. The book gives you the template; extension is where it sticks. - **Don't skip the testing chapters even if eager to deploy**: Unit tests and coverage measurement are what separate a tutorial project from something you'd actually maintain. 【Coverage Limits】 The excerpts cover the full table of contents and detailed content through the database/model chapters, but later chapters on Blueprint, unit testing, and coverage are only visible as titles — specific implementation details for those topics are not covered in the available excerpts.
Excerpt 1
files - Allowing you to work with images and stylesheets 28. Create a decorator for login authentication 29. Splitting an Application with Blueprint 30. Writ...
View in text
Excerpt 2
objects called models as needed during processing (Model) 4. Return a template, such as HTML, to be displayed to the user at the end of the process (Template...
View in text
Excerpt 3
eate a base layout template We created index.html and login.html in the previous chapter, but they are identical except in <div class="blog-body"></div>. Fro...
View in text
Excerpt 4
ogout') def logout(): session.pop('logged_in', None) flash('Logged Out') return redirect(url_for('show_entries')) It changes the redirect('/') to url_for('sh...
View in text
Excerpt 5
elif request.form['password'] != app.config['PASSWORD']: flash('Password is different') else: session['logged_in'] = True flash('Login successful') return re...
View in text
Excerpt 6
ethod="GET"> <button type="submit" class="btn btn- secondary">Edit</button> </form> </div> {% endblock %} Add edit_entry view Add the edit_entry view in view...
View in text
Excerpt 7
url_prefix here for entry views. I prefix /users this time. You can also add dynamic prefixes such as /<user_id> and user ID. Finally, since there is no long...
View in text
Excerpt 8
o we have to add a test for it. Final application structure Now that you’ve written all the code, let’s review the final application structure and roles. The...
View in text
Tags
AI categories
PythonWeb TechnologyBackend
Publish Year: 2019
Language: English
File Format: PDF
File Size: 2.8 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…