Flask (web framework)

From Wikipedia, the free encyclopedia
(Redirected from Flask (programming))
Jump to navigation Jump to search
Flask
DeveloperArmin Ronacher
Initial release1 April 2010; 16 years ago (2010-04-01)
Repositorygithub.com/pallets/flask
Written inPython
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    TypeWeb framework
    LicenseBSD 3-clause license
    Websitepalletsprojects.com/p/flask/

    Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.[1] It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions. However, Flask supports extensions that can add application features as if they were implemented in Flask itself. Extensions exist for object-relational mappers, form validation, upload handling, various open authentication technologies and several common framework related tools.[2]

    Applications that use the Flask framework include Pinterest and LinkedIn.[3][4]

    History

    [edit | edit source]

    Flask was created by Armin Ronacher of Pocoo, an international group of Python enthusiasts formed in 2004.[5] According to Ronacher, the idea was originally an April Fool's joke that was popular enough to make into a serious application.[6][7][8] The name is a play on the earlier Bottle framework.[6]

    When Ronacher and Georg Brandl created a bulletin board system written in Python in 2004, the Pocoo projects Werkzeug and Jinja were developed.[9]

    In April 2016, the Pocoo team was disbanded and development of Flask and related libraries passed to the newly formed Pallets project.[10][11] Since 2018, Flask-related data and objects can be rendered with Bootstrap.[12]

    Flask has become popular among Python enthusiasts. As of October 2020, it has the second-most number of stars on GitHub among Python web-development frameworks, only slightly behind Django,[13] and was voted the most popular web framework in the Python Developers Survey for years between and including 2018 and 2022.[14][15][16][17][18]

    Components

    [edit | edit source]

    The microframework Flask is part of the Pallets Projects (formerly Pocoo), and based on several others of them, all under a BSD license.

    Werkzeug

    [edit | edit source]

    Werkzeug (German for "tool") is a utility library for the Python programming language for Web Server Gateway Interface (WSGI) applications. Werkzeug can instantiate objects for request, response, and utility functions. It can be used as the basis for a custom software framework and supports Python 2.7 and 3.5 and later.[19][20]

    Jinja

    [edit | edit source]

    Jinja, also by Ronacher, is a template engine for the Python programming language. Similar to the Django web framework, it handles templates in a sandbox.

    MarkupSafe

    [edit | edit source]

    MarkupSafe is a string handling library for the Python programming language. The eponymous MarkupSafe type extends the Python string type and marks its contents as "safe"; combining MarkupSafe with regular strings automatically escapes the unmarked strings, while avoiding double escaping of already marked strings.

    ItsDangerous

    [edit | edit source]

    ItsDangerous is a safe data serialization library for the Python programming language. It is used to store the session of a Flask application in a cookie without allowing users to tamper with the session contents.

    Click

    [edit | edit source]

    Click is a Python package used by Flask to create command-line interfaces (CLI) by providing a simple and composable way to define commands, arguments, and options.

    Features

    [edit | edit source]
    • Development server and debugger
    • Integrated support for unit testing
    • RESTful request dispatching
    • Uses Jinja templating
    • Support for secure cookies (client side sessions)
    • 100% WSGI 1.0 compliant
    • Unicode-based
    • Complete documentation
    • Google App Engine compatibility
    • Extensions available to extend functionality

    Example

    [edit | edit source]

    The following code shows a simple web application that displays "Hello World!" when visited:

    from flask import Flask
    app = Flask(__name__)
    
    @app.route("/")
    def hello() -> str:
        return "Hello World"
    
    
    if __name__ == "__main__":
        app.run()
    

    Render Template with Flask

    [edit | edit source]
    from flask import Flask, render_template
    
    app = Flask(__name__)
    
    @app.route("/")
    def message():
      message = "Hello World!"
    
      return render_template("index.html",message=message)
    

    Jinja in HTML for the Render Template

    [edit | edit source]
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>{{ message }}</title>
    </head>
    <body>
        <p>{{ message }}</p>
    </body>
    </html>
    

    See also

    [edit | edit source]

    Lua error in mw.title.lua at line 392: bad argument #2 to 'title.new' (unrecognized namespace name 'Portal').

    References

    [edit | edit source]
    1. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    3. ^ What challenges has Pinterest encountered with Flask?
    4. ^ Rachel Sanders: Developing Flask Extensions - PyCon 2014
    5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    6. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    7. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    8. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    9. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    10. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    11. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    12. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    13. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    14. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    15. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    16. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    17. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    18. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    19. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    20. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    [edit | edit source]
    • Lua error in Module:Official_website at line 94: attempt to index field 'wikibase' (a nil value).