万本电子书0元读

万本电子书0元读

顶部广告

Learning Flask Framework电子书

售       价:¥

59人正在读 | 0人评论 9.8

作       者:Matt Copperwaite

出  版  社:Packt Publishing

出版时间:2015-11-26

字       数:126.7万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:此类商品不支持退换货,不支持下载打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Build dynamic, data-driven websites and modern web applications with Flask About This Book Discover the most popular Flask resources on the web with ease Familiarize yourself with third-party libraries commonly used with Flask Create a fast, interactive, and secure web app with this hands-on guide Who This Book Is For This book is for anyone who wants to develop their knowledge of Python into something that can be used on the web. Flask follows the Python design principles and can be easily understood by anyone who knows Python, and even by those who do not. What You Will Learn Create your web pages to add modularity and flexibility to your web app using templates Store and retrieve relational data using SQLAlchemy Develop schema migrations with Alembic Produce an admin section using flask-admin Build RESTful APIs using Flask-Restless Simulate requests and sessions using the Flask test client Make Ajax requests from Jinja2 templates In Detail Flask is a small and powerful web development framework for Python. It does not presume or force a developer to use a particular tool or library. Flask supports extensions that can add application features as if they were implemented in Flask itself. Flask’s main task is to build web applications quickly and with less code. With its lightweight and efficient web development framework, Flask combines rapid development and clean, simple design. This book will take you through the basics of learning how to apply your knowledge of Python to the web. Starting with the creation of a “Hello world” Flask app, you will be introduced to the most common Flask APIs and Flask’s interactive debugger. You will learn how to store and retrieve blog posts from a relational database using an ORM and also to map URLs to views. Furthermore, you will walk through template blocks, inheritance, file uploads, and static assets. You will learn to authenticate users, build log in/log out functionality, and add an administrative dashboard for the blog. Moving on, you will discover how to make Ajax requests from the template and see how the Mock library can simplify testing complex interactions. Finally, you will learn to deploy Flask applications securely and in an automated, repeatable manner, and explore some of the most popular Flask resources on the web. Style and approach A comprehensive guide packed with real-world examples and popular use cases; starting with basic overviews and diving into the practical aspects of Flask Framework.
目录展开

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

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部