Flask (web framework)#Example
{{short description|Python web framework}}
{{Primary sources|date=April 2024}}
{{Infobox software
| name = Flask
| logo = Flask logo.svg{{!}}class=skin-invert
| developer = Armin Ronacher
| released = {{Start date and age|2010|04|01|df=y}}
| latest release version = {{wikidata|property|reference|edit|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}}
| repo = {{URL|https://github.com/pallets/flask}}
| programming language = Python
| genre = Web framework
| license = BSD 3-clause license
| website = {{URL|https://palletsprojects.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.{{Cite web|url = http://flask.pocoo.org:80/docs/0.10/foreword|archive-url = https://web.archive.org/web/20171117015927/http://flask.pocoo.org/docs/0.10/foreword|url-status = dead|archive-date = 2017-11-17|title = Flask Foreword}} 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.{{Cite web|url = http://flask.pocoo.org/extensions/|archive-url = https://web.archive.org/web/20180517082208/http://flask.pocoo.org/extensions/|url-status = dead|archive-date = 2018-05-17|title = Flask Extensions}}
Applications that use the Flask framework include Pinterest and LinkedIn.[http://www.quora.com/What-challenges-has-Pinterest-encountered-with-Flask/answer/Steve-Cohen?srid=hXZd&share=1 What challenges has Pinterest encountered with Flask?][https://www.youtube.com/watch?v=OXN3wuHUBP0#t=46 Rachel Sanders: Developing Flask Extensions - PyCon 2014]
History
Flask was created by Armin Ronacher of Pocoo, an international group of Python enthusiasts formed in 2004.{{Cite web |archive-url = https://web.archive.org/web/20180315200205/http://www.pocoo.org/team/ |archive-date=2018-03-15 |url=http://www.pocoo.org/team/ |title = Pocoo Team}} According to Ronacher, the idea was originally an April Fool's joke that was popular enough to make into a serious application.{{cite web |archive-url=https://web.archive.org/web/20161217230320/http://mitsuhiko.pocoo.org/flask-pycon-2011.pdf |archive-date=2016-12-17 |url=http://mitsuhiko.pocoo.org/flask-pycon-2011.pdf |title=Opening the Flask |first=Armin |last=Ronacher |access-date=2011-09-30}}{{cite web |archive-url=https://web.archive.org/web/20180514202042/https://lucumr.pocoo.org/2010/4/3/april-1st-post-mortem/ |url=https://lucumr.pocoo.org/2010/4/3/april-1st-post-mortem/ |archive-date=2018-05-14 |title=April 1st Post Mortem|last=Ronacher|first=Armin|date=3 April 2010|work=Armin Ronacher's Thoughts and Writings|url-status=live|access-date=2015-07-25}}{{cite web | title=Denied: the next generation python micro-web-framework (April Fools page) | url=http://denied.immersedcode.org/ | access-date=2011-09-30 | url-status=dead | archive-url=https://web.archive.org/web/20110904053655/http://denied.immersedcode.org/ | archive-date=2011-09-04 }} The name is a play on the earlier Bottle framework.
When Ronacher and Georg Brandl created a bulletin board system written in Python in 2004, the Pocoo projects Werkzeug and Jinja were developed.{{Cite web |archive-url = https://web.archive.org/web/20171119213325/http://www.pocoo.org/history/ |archive-date = 2017-11-19 |url = http://www.pocoo.org:80/history/ |title = History |publisher = Pocoo Team |access-date = 2015-03-25 |url-status = dead }}
In April 2016, the Pocoo team was disbanded and development of Flask and related libraries passed to the newly formed Pallets project.{{Cite web|last=Ronacher|first=Armin|date=2016-04-01|title=Hello Pallets Users|url=https://palletsprojects.com/blog/hello/|access-date=2021-05-08|website=The Pallets Projects}}{{Cite web|title=Pocoo|url=https://www.pocoo.org/|access-date=2021-05-08|website=www.pocoo.org}} Since 2018, Flask-related data and objects can be rendered with Bootstrap.{{Cite web |url = https://github.com/helloflask/bootstrap-flask|title = Bootstrap-Flask|access-date = 2022-11-06|publisher = HelloFlask}}
Flask has become popular among Python enthusiasts. {{As of|2020|10|post=,}} it has the second-most number of stars on GitHub among Python web-development frameworks, only slightly behind Django,{{Cite web|url=https://github.com/search?l=Python&q=stars%3A%3E100&s=stars&type=Repositories|title=Python libraries by GitHub stars|website=Github|access-date=2020-01-27}} and was voted the most popular web framework in the Python Developers Survey for years between and including 2018 and 2022.{{Cite web |url = https://www.jetbrains.com/research/python-developers-survey-2018/|title = Python Developers Survey 2018|date = 2018-11-01|publisher = www.jetbrains.com}}{{Cite web |url = https://www.jetbrains.com/lp/python-developers-survey-2019/|title = Python Developers Survey 2019|date = 2019|publisher = www.jetbrains.com}}{{Cite web |url = https://www.jetbrains.com/lp/python-developers-survey-2020/|title = Python Developers Survey 2020|date = 2020|publisher = www.jetbrains.com}}{{Cite web |date=2021 |title=Python Developers Survey 2021 |url=https://lp.jetbrains.com/python-developers-survey-2021/ |publisher=www.jetbrains.com}}{{Cite web |title=Python Developers Survey 2022 Results |url=https://lp.jetbrains.com/python-developers-survey-2022/ |access-date=2023-10-17 |website=www.jetbrains.com. 2022. |language=en}}
Components
The microframework Flask is part of the Pallets Projects (formerly Pocoo), and based on several others of them, all under a BSD license.
= Werkzeug =
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.{{cite web|last1=Ronacher|first1=Armin|title=Werkzeug The Python WSGI Utility Library|url=https://www.palletsprojects.com/p/werkzeug/|website=palletsprojects.com|access-date=27 May 2018}}{{cite web|last1=Ronacher|first1=Armin|title=Installation, Python Version|url=https://werkzeug.palletsprojects.com/en/1.0.x/installation/#python-version|website=palletsprojects.com|access-date=20 April 2020|archive-date=11 May 2021|archive-url=https://web.archive.org/web/20210511212501/https://werkzeug.palletsprojects.com/en/1.0.x/installation/#python-version|url-status=dead}}
= Jinja =
{{main|Jinja (template engine)}}
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 =
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 =
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.
Features
- 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
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()
See also
{{Portal|Free and open-source software}}
References
{{Reflist|30em}}
External links
- {{Official website}}
{{Python (programming language)}}
{{Python web frameworks}}
{{Web frameworks}}
{{DEFAULTSORT:Flask (Programming)}}
Category:Free software programmed in Python
Category:Python (programming language) web frameworks
Category:Software using the BSD license
Category:Articles with example Python (programming language) code