售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Learning Flask Framework
Table of Contents
Learning Flask Framework
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Creating Your First Flask Application
What is Flask?
With great freedom comes great responsibility
Setting up a development environment
Supporting Python 3
Installing Python packages
Installing pip
Installing virtualenv
Why use virtualenv?
Installing virtualenv with pip
Creating your first Flask app
Installing Flask in your virtualenv
Hello, Flask!
Understanding the code
Routes and requests
Reading values from the request
Debugging Flask applications
Introducing the blog project
The spec
Creating the blog project
A barebones Flask app
Zooming out
The import flow
Summary
2. Relational Databases with SQLAlchemy
Why use a relational database?
Introducing SQLAlchemy
Installing SQLAlchemy
Using SQLAlchemy in our Flask app
Choosing a database engine
Connecting to the database
Creating the Entry model
Creating the Entry table
Working with the Entry model
Making changes to an existing entry
Deleting an entry
Retrieving blog entries
Filtering the list of entries
Special lookups
Combining expressions
Negation
Operator precedence
Building a tagging system
Adding and removing tags from entries
Using backrefs
Making changes to the schema
Adding Flask-Migrate to our project
Creating the initial migration
Adding a status column
Summary
3. Templates and Views
Introducing Jinja2
Basic template operations
Loops, control structures, and template programming
Jinja2 built-in filters
Creating a base template for the blog
Creating a URL scheme
Defining the URL routes
Building the index view
Building the detail view
Listing entries matching a given tag
Listing all the tags
Full-text search
Adding pagination links
Enhancing the blog app
Summary
4. Forms and Validation
Getting started with WTForms
Defining a form for the Entry model
A form with a view
The create.html template
Handling form submissions
Validating input and displaying error messages
Editing existing entries
The edit.html template
Deleting entries
Cleaning up
Using flash messages
Displaying flash messages in the template
Saving and modifying tags on posts
Image uploads
Processing file uploads
The image upload template
Serving static files
Summary
5. Authenticating Users
Creating a user model
Installing Flask-Login
Implementing the Flask-Login interface
Creating user objects
Login and logout views
The login template
Logging out
Accessing the current user
Restricting access to views
Storing an entry's author
Setting the author on blog entries
Protecting the edit and delete views
Displaying a user's drafts
Sessions
Summary
6. Building an Administrative Dashboard
Installing Flask-Admin
Adding Flask-Admin to our app
Exposing models through the Admin
Customizing the list views
Adding search and filtering to the list view
Customizing Admin model forms
Enhancing the User form
Generating slugs
Managing static assets via the Admin
Securing the admin website
Creating an authentication and authorization mixin
Setting up a custom index page
Flask-Admin templates
Reading more
Summary
7. AJAX and RESTful APIs
Creating a comment model
Creating a schema migration
Installing Flask-Restless
Setting up Flask-Restless
Making API requests
Creating comments using AJAX
AJAX form submissions
Validating data in the API
Preprocessors and postprocessors
Loading comments using AJAX
Retrieving the list of comments
Reading more
Summary
8. Testing Flask Apps
Unit testing
Python's unit test module
A simple math test
Flask and unit testing
Testing a page
Testing an API
Test-friendly configuration
Mocking objects
Logging and error reporting
Logging
Logging to file
Custom log messages
Levels
Error reporting
Read more
Summary
9. Excellent Extensions
SeaSurf and CSRF protection of forms
Creating Atom feeds
Syntax highlighting using Pygments
Simple editing with Markdown
Caching with Flask-Cache and Redis
Creating secure, stable versions of your site by creating static content
Commenting on a static site
Synchronizing multiple editors
Asynchronous tasks with Celery
Creating command line instructions with Flask-script
References
Summary
10. Deploying Your Application
Running Flask with a WSGI server
Apache's httpd
Serving static files
Nginx
Serving static files
Gunicorn
Securing your site with SSL
Getting your certificate
Apache httpd
Nginx
Gunicorn
Automating deployment using Ansible
Read more
Summary
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜