Flask API

Table of Contents

  • Flask interfaces — API
    • 1. Application Object
    • 2. Blueprint Objects
    • 3. Incoming Request Data
    • 4. Response Objects
    • 5. Sessions
    • 6. Session Interface
    • 7. Test Client
    • 8. Application Globals
    • 9. Useful Functions and Classes
    • 10. Message Flashing
    • 11. JSON Support
    • 12. Template Rendering
    • 13. Configuration
    • 14. Extensions
    • 15. Stream Helpers
    • 16. Useful Internals
    • 17. Signals
    • 18. Class-Based Views
    • 19. URL Route Registrations
    • 20. View Function Options
    • 21. Command Line Interface
  • Flask Tutorial
    • Introducing Flaskr
    • Step 0: Creating The Folders
    • Step 1: Database Schema
    • Step 2: Application Setup Code
    • Step 3: Installing flaskr with setuptools
    • Step 4: Database Connections
    • Step 5: Creating The Database
    • Step 7: The View Functions
      • Show Entries
      • Add New Entry
      • Login and Logout
    • Step 8: The Templates
      • layout.html
      • show_entries.html
      • login.html
    • Step 9: Adding Style
    • Bonus: Testing the Application
    • Adding Tests to flaskr
    • Testing + Setuptools
  • Flask — Quickstart
    • 1. A Minimal Application
    • 2. What to do if the Server does not Start
      • 2.1. Old Version of Flask
      • 2.2. Invalid Import Name
    • 3. Debug Mode
    • 4. Routing
      • 4.1. Variable Rules
      • 4.2. URL Building
      • 4.3. HTTP Methods
    • 5. Static Files
    • 6. Rendering Templates
    • 7. Accessing Request Data
      • 7.1. Context Locals
      • 7.2. The Request Object
      • 7.3. File Uploads
      • 7.4. Cookies
    • 8. Redirects and Errors
    • 9. About Responses
    • 10. Sessions
    • 11. Message Flashing
    • 12. Logging
    • 13. Hooking in WSGI Middlewares
    • 14. Using Flask Extensions
    • 15. Deploying to a Web Server
  • 1   Flask — Templates
    • 1.1   Jinja Setup
    • 1.2   Standard Context
    • 1.3   Standard Filters
    • 1.4   Controlling Autoescaping
    • 1.5   Registering Filters
    • 1.6   Context Processors
  • 1   Configuration Handling
    • 1.1   Configuration Basics
    • 1.2   Builtin Configuration Values
    • 1.3   Configuring from Files
    • 1.4   Configuration Best Practices
    • 1.5   Development / Production
    • 1.6   Instance Folders
  • 1   Testing Flask Applications
    • 1.1   The Application
    • 1.2   The Testing Skeleton
    • 1.3   The First Test
    • 1.4   Logging In and Out
    • 1.5   Test Adding Messages
    • 1.6   Other Testing Tricks
    • 1.7   Faking Resources and Context
    • 1.8   Keeping the Context Around
    • 1.9   Accessing and Modifying Sessions
  • Patterns for Flask (part1)
    • 1. Larger Applications
      • 1.1. Simple Packages
      • 1.2. Working with Blueprints
    • 2. Application Factories
      • 2.1. Basic Factories
      • 2.2. Factories & Extensions
      • 2.3. Using Applications
      • 2.4. Factory Improvements
    • 3. Application Dispatching
      • 3.1. Working with this Document
      • 3.2. Combining Applications
      • 3.3. Dispatch by Subdomain
      • 3.4. Dispatch by Path
    • 4. Implementing API Exceptions
      • 4.1. Simple Exception Class
      • 4.2. Registering an Error Handler
      • 4.3. Usage in Views
    • 5. Using URL Processors
      • 5.1. Internationalized Application URLs
      • 5.2. Internationalized Blueprint URLs
    • 6. Deploying with Setuptools
      • 6.1. Basic Setup Script
      • 6.2. Tagging Builds
      • 6.3. Distributing Resources
      • 6.4. Declaring Dependencies
      • 6.5. Installing / Developing
    • 7. Deploying with Fabric
      • 7.1. Creating the first Fabfile
      • 7.2. Running Fabfiles
      • 7.3. The WSGI File
      • 7.4. The Configuration File
      • 7.5. First Deployment
      • 7.6. Next Steps
    • 8. Using SQLite 3 with Flask
      • 8.1. Connect on Demand
      • 8.2. Easy Querying
      • 8.3. Initial Schemas
    • 9. SQLAlchemy in Flask
      • 9.1. Flask-SQLAlchemy Extension
      • 9.2. Declarative
      • 9.3. Manual Object Relational Mapping
      • 9.4. SQL Abstraction Layer
    • 10. Uploading Files
      • 10.1. A Gentle Introduction
      • 10.2. Improving Uploads
      • 10.3. Upload Progress Bars
      • 10.4. An Easier Solution
    • 11. Caching
      • 11.1. Setting up a Cache
      • 11.2. Using a Cache
    • 12. View Decorators
      • 12.1. Login Required Decorator
      • 12.2. Caching Decorator
      • 12.3. Templating Decorator
      • 12.4. Endpoint Decorator
    • 13. Form Validation with WTForms
      • 13.1. The Forms
      • 13.2. In the View
      • 13.3. Forms in Templates
  • Patterns for Flask (part2)
    • 1. Template Inheritance
      • 1.1. Base Template
      • 1.2. Child Template
    • 2. Message Flashing
      • 2.1. Simple Flashing
      • 2.2. Flashing With Categories
      • 2.3. Filtering Flash Messages
    • 3. AJAX with jQuery
      • 3.1. Loading jQuery
      • 3.2. Where is My Site?
      • 3.3. JSON View Functions
      • 3.4. The HTML
    • 4. Custom Error Pages
      • 4.1. Common Error Codes
      • 4.2. Error Handlers
    • 5. Lazily Loading Views
      • 5.1. Converting to Centralized URL Map
      • 5.2. Loading Late
    • 6. MongoKit in Flask
      • 6.1. Declarative
      • 6.2. PyMongo Compatibility Layer
    • 7. Adding a favicon
      • 7.1. See also
    • 8. Streaming Contents
      • 8.1. Basic Usage
      • 8.2. Streaming from Templates
      • 8.3. Streaming with Context
    • 9. Deferred Request Callbacks
      • 9.1. The Decorator
      • 9.2. Calling the Deferred
      • 9.3. A Practical Example
    • 10. Adding HTTP Method Overrides
    • 11. Request Content Checksums
    • 12. Celery Based Background Tasks
      • 12.1. Installing Celery
      • 12.2. Configuring Celery
      • 12.3. Minimal Example
      • 12.4. Running the Celery Worker
    • 13. Subclassing Flask
  • Deployment Options
    • Hosted options
    • Self-hosted options
      • 1. mod_wsgi (Apache)
        • 1.1. Installing mod_wsgi
        • 1.2. Creating a .wsgi file
        • 1.3. Configuring Apache
        • 1.4. Troubleshooting
        • 1.5. Support for Automatic Reloading
        • 1.6. Working with Virtual Environments
      • 2. Standalone WSGI Containers
        • 2.1. Gunicorn
        • 2.2. Gevent
        • 2.3. Twisted Web
        • 2.4. Proxy Setups
      • 3. uWSGI
        • 3.1. Starting your app with uwsgi
        • 3.2. Configuring nginx
      • 4. FastCGI
        • 4.1. Creating a .fcgi file
        • 4.2. Configuring Apache
        • 4.3. Configuring lighttpd
        • 4.4. Configuring nginx
        • 4.5. Running FastCGI Processes
        • 4.6. Debugging
      • 5. CGI
        • 5.1. Creating a .cgi file
        • 5.2. Server Setup
  • Other Flask doc materials
    • 1. Foreword
      • 1.1. What does “micro” mean?
      • 1.2. Configuration and Conventions
      • 1.3. Growing with Flask
    • 2. Foreword for Experienced Programmers
      • 2.1. Thread-Locals in Flask
      • 2.2. Develop for the Web with Caution
      • 2.3. Python 3 Support in Flask
    • 3. Installation
      • 3.1. virtualenv
      • 3.2. System-Wide Installation
      • 3.3. Living on the Edge
      • 3.4. pip and setuptools on Windows
    • 4. Application Errors
      • 4.1. Error Logging Tools
      • 4.2. Error handlers
        • 4.2.1. Registering
        • 4.2.2. Handling
      • 4.3. Error Mails
      • 4.4. Logging to a File
      • 4.5. Controlling the Log Format
        • 4.5.1. Email
        • 4.5.2. File logging
        • 4.5.3. Complex Log Formatting
      • 4.6. Other Libraries
    • 5. Debugging Application Errors
      • 5.1. When in Doubt, Run Manually
      • 5.2. Working with Debuggers
    • 6. Signals
      • 6.1. Subscribing to Signals
      • 6.2. Creating Signals
      • 6.3. Sending Signals
      • 6.4. Signals and Flask’s Request Context
      • 6.5. Decorator Based Signal Subscriptions
      • 6.6. Core Signals
    • 7. Pluggable Views
      • 7.1. Basic Principle
      • 7.2. Method Hints
      • 7.3. Method Based Dispatching
      • 7.4. Decorating Views
      • 7.5. Method Views for APIs
    • 8. The Application Context
      • 8.1. Purpose of the Application Context
      • 8.2. Creating an Application Context
      • 8.3. Locality of the Context
      • 8.4. Context Usage
    • 9. The Request Context
      • 9.1. Diving into Context Locals
      • 9.2. How the Context Works
      • 9.3. Callbacks and Errors
      • 9.4. Teardown Callbacks
      • 9.5. Notes On Proxies
      • 9.6. Context Preservation on Error
    • 10. Modular Applications with Blueprints
      • 10.1. Why Blueprints?
      • 10.2. The Concept of Blueprints
      • 10.3. My First Blueprint
      • 10.4. Registering Blueprints
      • 10.5. Blueprint Resources
        • 10.5.1. Blueprint Resource Folder
        • 10.5.2. Static Files
        • 10.5.3. Templates
      • 10.6. Building URLs
      • 10.7. Error Handlers
    • 11. Flask Extensions
      • 11.1. Finding Extensions
      • 11.2. Using Extensions
      • 11.3. Building Extensions
      • 11.4. Flask Before 0.8
    • 12. Command Line Interface
      • 12.1. Basic Usage
      • 12.2. Virtualenv Integration
      • 12.3. Debug Flag
      • 12.4. Running a Shell
      • 12.5. Custom Commands
      • 12.6. Application Context
      • 12.7. Factory Functions
      • 12.8. Custom Scripts
      • 12.9. CLI Plugins
    • 13. Development Server
      • 13.1. Command Line
      • 13.2. In Code
    • 14. Working with the Shell
      • 14.1. Command Line Interface
      • 14.2. Creating a Request Context
      • 14.3. Firing Before/After Request
      • 14.4. Further Improving the Shell Experience
    • 15. Becoming Big
      • 15.1. Read the Source.
      • 15.2. Hook. Extend.
      • 15.3. Subclass.
      • 15.4. Wrap with middleware.
      • 15.5. Fork.
      • 15.6. Scale like a pro.
      • 15.7. Discuss with the community.
  • Flask doc — Additional Notes
    • 1. Design Decisions in Flask
      • 1.1. The Explicit Application Object
      • 1.2. The Routing System
      • 1.3. One Template Engine
      • 1.4. Micro with Dependencies
      • 1.5. Thread Locals
      • 1.6. What Flask is, What Flask is Not
    • 2. HTML/XHTML FAQ
      • 2.1. History of XHTML
      • 2.2. History of HTML5
      • 2.3. HTML versus XHTML
      • 2.4. What does “strict” mean?
      • 2.5. New technologies in HTML5
      • 2.6. What should be used?
    • 3. Security Considerations
      • 3.1. Cross-Site Scripting (XSS)
      • 3.2. Cross-Site Request Forgery (CSRF)
      • 3.3. JSON Security
    • 4. Unicode in Flask
      • 4.1. Automatic Conversion
      • 4.2. The Golden Rule
      • 4.3. Encoding and Decoding Yourself
      • 4.4. Configuring Editors
    • 5. Flask Extension Development
      • 5.1. Anatomy of an Extension
      • 5.2. “Hello Flaskext!”
        • 5.2.1. setup.py
        • 5.2.2. flask_sqlite3.py
      • 5.3. Initializing Extensions
      • 5.4. The Extension Code
      • 5.5. Using _app_ctx_stack
      • 5.6. Teardown Behavior
      • 5.7. Learn from Others
      • 5.8. Approved Extensions
      • 5.9. Extension Import Transition
    • 6. Pocoo Styleguide
      • 6.1. General Layout
      • 6.2. Expressions and Statements
      • 6.3. Naming Conventions
      • 6.4. Docstrings
      • 6.5. Comments
  • Werkzeug doc materials
    • 1. Werkzeug Tutorial
      • 1.1. Introducing Shortly
      • 1.2. Step 0: A Basic WSGI Introduction
      • 1.3. Step 1: Creating the Folders
      • 1.4. Step 2: The Base Structure
      • 1.5. Intermezzo: Running the Application
      • 1.6. Step 3: The Environment
      • 1.7. Step 4: The Routing
      • 1.8. Step 5: The First View
      • 1.9. Step 6: Redirect View
      • 1.10. Step 7: Detail View
      • 1.11. Step 8: Templates
      • 1.12. Step 9: The Style
      • 1.13. Bonus: Refinements
    • 2. Quickstart
      • 2.1. WSGI Environment
      • 2.2. Enter Request
      • 2.3. Header Parsing
      • 2.4. Responses
    • 3. Application Deployment
      • 3.1. CGI
        • 3.1.1. Creating a .cgi file
        • 3.1.2. Server Setup
      • 3.2. mod_wsgi (Apache)
        • 3.2.1. Installing mod_wsgi
        • 3.2.2. Creating a .wsgi file
        • 3.2.3. Configuring Apache
      • 3.3. FastCGI
        • 3.3.1. Creating a .fcgi file
        • 3.3.2. Configuring lighttpd
        • 3.3.3. Configuring nginx
        • 3.3.4. Debugging
      • 3.4. HTTP Proxying
        • 3.4.1. Creating a .py server
        • 3.4.2. Configuring nginx

Auto-generated API

  • flask
    • Functions
      • flask.after_this_request
      • flask.copy_current_request_context
      • flask.escape
      • flask.flash
      • flask.get_flashed_messages
      • flask.get_template_attribute
      • flask.has_app_context
      • flask.has_request_context
      • flask.jsonify
      • flask.make_response
      • flask.redirect
      • flask.render_template
      • flask.render_template_string
      • flask.safe_join
      • flask.send_file
      • flask.send_from_directory
      • flask.stream_with_context
      • flask.url_for
    • Classes
      • flask.Blueprint
        • Methods
        • Attributes
      • flask.Config
        • Methods
      • flask.Flask
        • Methods
        • Attributes
      • flask.Markup
        • Methods
      • flask.Request
        • Methods
        • Attributes
      • flask.Response
        • Methods
        • Attributes
      • flask.Session
        • Methods
        • Attributes
  • werkzeug
    • Functions
      • werkzeug.append_slash_redirect
      • werkzeug.bind_arguments
      • werkzeug.check_password_hash
      • werkzeug.cookie_date
      • werkzeug.create_environ
      • werkzeug.dump_cookie
      • werkzeug.dump_header
      • werkzeug.dump_options_header
      • werkzeug.escape
      • werkzeug.extract_path_info
      • werkzeug.find_modules
      • werkzeug.format_string
      • werkzeug.generate_etag
      • werkzeug.generate_password_hash
      • werkzeug.get_current_url
      • werkzeug.get_host
      • werkzeug.http_date
      • werkzeug.import_string
      • werkzeug.iri_to_uri
      • werkzeug.is_entity_header
      • werkzeug.is_hop_by_hop_header
      • werkzeug.is_resource_modified
      • werkzeug.make_line_iter
      • werkzeug.parse_accept_header
      • werkzeug.parse_authorization_header
      • werkzeug.parse_cache_control_header
      • werkzeug.parse_cookie
      • werkzeug.parse_date
      • werkzeug.parse_dict_header
      • werkzeug.parse_etags
      • werkzeug.parse_form_data
      • werkzeug.parse_list_header
      • werkzeug.parse_options_header
      • werkzeug.parse_set_header
      • werkzeug.parse_www_authenticate_header
      • werkzeug.peek_path_info
      • werkzeug.pop_path_info
      • werkzeug.quote_etag
      • werkzeug.quote_header_value
      • werkzeug.redirect
      • werkzeug.release_local
      • werkzeug.remove_entity_headers
      • werkzeug.remove_hop_by_hop_headers
      • werkzeug.responder
      • werkzeug.run_simple
      • werkzeug.run_wsgi_app
      • werkzeug.secure_filename
      • werkzeug.test_app
      • werkzeug.unescape
      • werkzeug.unquote_etag
      • werkzeug.unquote_header_value
      • werkzeug.uri_to_iri
      • werkzeug.url_decode
      • werkzeug.url_encode
      • werkzeug.url_fix
      • werkzeug.url_quote
      • werkzeug.url_quote_plus
      • werkzeug.url_unquote
      • werkzeug.url_unquote_plus
      • werkzeug.validate_arguments
      • werkzeug.wrap_file
    • Classes
      • werkzeug.Aborter
        • Methods
      • werkzeug.Accept
        • Methods
        • Attributes
      • werkzeug.AcceptMixin
        • Attributes
      • werkzeug.Authorization
        • Methods
        • Attributes
      • werkzeug.AuthorizationMixin
        • Attributes
      • werkzeug.BaseRequest
        • Methods
        • Attributes
      • werkzeug.BaseResponse
        • Methods
        • Attributes
      • werkzeug.CallbackDict
        • Methods
        • Attributes
      • werkzeug.CharsetAccept
        • Methods
        • Attributes
      • werkzeug.Client
        • Methods
      • werkzeug.ClosingIterator
        • Methods
      • werkzeug.CombinedMultiDict
        • Methods
      • werkzeug.CommonRequestDescriptorsMixin
        • Attributes
      • werkzeug.CommonResponseDescriptorsMixin
        • Attributes
      • werkzeug.DebuggedApplication
        • Methods
        • Attributes
      • werkzeug.DispatcherMiddleware
        • Methods
      • werkzeug.ETagRequestMixin
        • Attributes
      • werkzeug.ETagResponseMixin
        • Methods
        • Attributes
      • werkzeug.ETags
        • Methods
      • werkzeug.EnvironBuilder
        • Methods
        • Attributes
      • werkzeug.EnvironHeaders
        • Methods
      • werkzeug.FileMultiDict
        • Methods
      • werkzeug.FileStorage
        • Methods
        • Attributes
      • werkzeug.FileWrapper
        • Methods
      • werkzeug.HTMLBuilder
        • Methods
      • werkzeug.HeaderSet
        • Methods
      • werkzeug.Headers
        • Methods
      • werkzeug.Href
        • Methods
      • werkzeug.ImmutableDict
        • Methods
      • werkzeug.ImmutableList
        • Methods
      • werkzeug.ImmutableMultiDict
        • Methods
      • werkzeug.ImmutableOrderedMultiDict
        • Methods
      • werkzeug.ImmutableTypeConversionDict
        • Methods
      • werkzeug.LanguageAccept
        • Methods
        • Attributes
      • werkzeug.LimitedStream
        • Methods
        • Attributes
      • werkzeug.Local
        • Methods
      • werkzeug.LocalManager
        • Methods
      • werkzeug.LocalProxy
        • Methods
      • werkzeug.LocalStack
        • Methods
        • Attributes
      • werkzeug.MIMEAccept
        • Methods
        • Attributes
      • werkzeug.MultiDict
        • Methods
      • werkzeug.OrderedMultiDict
        • Methods
      • werkzeug.Request
        • Methods
        • Attributes
      • werkzeug.RequestCacheControl
        • Methods
        • Attributes
      • werkzeug.Response
        • Methods
        • Attributes
      • werkzeug.ResponseCacheControl
        • Methods
        • Attributes
      • werkzeug.ResponseStreamMixin
        • Attributes
      • werkzeug.SharedDataMiddleware
        • Methods
      • werkzeug.TypeConversionDict
        • Methods
      • werkzeug.UserAgent
        • Methods
      • werkzeug.UserAgentMixin
        • Attributes
      • werkzeug.WWWAuthenticate
        • Methods
        • Attributes
      • werkzeug.WWWAuthenticateMixin
        • Attributes
      • werkzeug.cached_property
        • Methods
        • Attributes
      • werkzeug.environ_property
        • Methods
        • Attributes
      • werkzeug.header_property
        • Methods
        • Attributes
    • Exceptions
      • werkzeug.ArgumentValidationError
Flask API
  • Docs »
  • Other Flask doc materials
  • View page source

Other Flask doc materials¶

Important

Content directly from official documentation page from Flask (link). I just created this page for my own liking since I love the readthedoc Sphinx theme.

  • http://flask.pocoo.org/docs/0.11/
  • https://github.com/pallets/flask/tree/master/docs

Contents¶

  • 1. Foreword
  • 2. Foreword for Experienced Programmers
  • 3. Installation
  • 4. Application Errors
  • 5. Debugging Application Errors
  • 6. Signals
  • 7. Pluggable Views
  • 8. The Application Context
  • 9. The Request Context
  • 10. Modular Applications with Blueprints
  • 11. Flask Extensions
  • 12. Command Line Interface
  • 13. Development Server
  • 14. Working with the Shell
  • 15. Becoming Big
Next Previous

Built with Sphinx using a theme provided by Read the Docs.