Flask插件

作者: 洞渊的自习室 | 来源:发表于2019-05-07 14:10 被阅读0次

    Flask的插件有很多,本文主要是对其中流行的(approved)的插件进行简单的展示。

    Flask-Babel

    Adds i18n/l10n support to Flask, based on babel and pytz.

    Flask-Bcrypt

    Bcrypt support for hashing passwords

    Flask-CouchDB

    Adds CouchDB support to Flask.

    Flask-Creole

    Creole parser filters for Flask.

    Flask-Dance

    Doing the OAuth dance with style using Flask, requests, and oauthlib.

    Flask-Exceptional

    Adds Exceptional support to Flask applications

    Flask-FlatPages

    Provides flat static pages to a Flask application, based on text files as opposed to a relational database.

    Flask-Genshi

    Adds support for the Genshi templating language to Flask applications.

    Flask-Login

    Flask-Login provides user session management for Flask. It handles the common tasks of logging in, logging out, and remembering your users' sessions over extended periods of time.

    Flask-Mail

    Makes sending mails from Flask applications very easy and has also support for unittesting.

    Flask-Misaka

    A simple extension to integrate the Misaka module for efficiently parsing Markdown.

    Flask-RESTful

    Flask-RESTful provides the building blocks for creating a great REST API.

    from flask import Flask, request
    from flask_restful import Resource, Api, reqparse, abort
    
    app = Flask(__name__)
    api = Api(app)
    
    TODOS = {
        'todo1': {'task': 'build an API'},
        'todo2': {'task': '?????'},
        'todo3': {'task': 'profit!'},
    }
    
    
    def abort_if_todo_doesnt_exists(todo_id):
        if todo_id not in TODOS:
            abort(404, message="Todo {} doesn't exist".format(todo_id))
    
    
    parser = reqparse.RequestParser()
    parser.add_argument('task', type=str)
    
    
    class Todo(Resource):
        def get(self, todo_id):
            abort_if_todo_doesnt_exists(todo_id)
            return TODOS[todo_id]
    
        def delete(self, todo_id):
            abort_if_todo_doesnt_exists(todo_id)
            del TODOS[todo_id]
            return '', 204
    
        def put(self, todo_id):
            args = parser.parse_args()
            task = {'task': args['task']}
            TODOS[todo_id] = task
            return task, 201
    
    
    class TodoList(Resource):
        def get(self):
            return TODOS
    
        def post(self):
            args = parser.parse_args()
            todo_id = int(max(TODOS.keys()).lstrip('todo')) + 1
            todo_id = 'todo{}'.format(todo_id)
            TODOS[todo_id] = {'task': args['task']}
            return TODOS[todo_id], 201
    
    
    api.add_resource(TodoList, '/todos')
    api.add_resource(Todo, '/todos/<todo_id>')
    
    
    if __name__ == '__main__':
        app.run(debug=True)
    

    Flask-Restless

    Flask-Restless provides simple generation of ReSTful APIs for database models defined using Flask-SQLAlchemy. The generated APIs send and receive messages in JSON format.

    Flask-Script

    The Flask-Script extension provides support for writing external scripts in Flask. It uses argparse to parse command line arguments.

    Flask-SeaSurf

    SeaSurf is a Flask extension for preventing cross-site request forgery (CSRF).

    Flask-SQLAlchemy

    Add SQLAlchemy support to Flask with automatic configuration and helpers to simplify common web use cases. Major features include:

    • Handle configuring one or more database connections.
    • Set up sessions scoped to the request/response cycle.
    • Time queries and track model changes for debugging.

    Flask-SSE

    Server Sent Events for Flask.

    Flask-Testing

    The Flask-Testing extension provides unit testing utilities for Flask.

    Flask-Themes

    Flask-Themes makes it easy for your application to support a wide range of appearances.

    Flask-Uploads

    Flask-Uploads allows your application to flexibly and efficiently handle file uploading and serving the uploaded files. You can create different sets of uploads - one for document attachments, one for photos, etc.

    Flask-User

    Customizable User Account Management for Flask: Register, Confirm email, Login, Change username, Change password, Forgot password, Role-based Authorization and Internationalization.

    Flask-WTF

    Flask-WTF offers simple integration with WTForms. This integration includes optional CSRF handling for greater security.

    Flask-XML-RPC

    Adds XML-RPC support to Flask.

    Flask-ZODB

    Use the ZODB with Flask

    Frozen-Flask

    Freezes a Flask application into a set of static files. The result can be hosted without any server-side software other than a traditional web server.

    另外也有一些虽然不是approved,但也很常用的插件

    Flask-Migrate

    SQLAlchemy database migrations for Flask applications using Alembic. The database operations are provided as command line arguments forFlask-Script.

    相关文章

      网友评论

        本文标题:Flask插件

        本文链接:https://www.haomeiwen.com/subject/zqyeoqtx.html