Nothing Special   »   [go: up one dir, main page]

Flask

Flask (source code) is a Python web framework built with a small core and easy-to-extend philosophy.

Official Flask logo. Flask Artwork License.

Why is Flask a good web framework choice?

Flask is considered more Pythonic than the Django web framework because in common situations the equivalent Flask web application is more explicit. Flask is also easy to get started with as a beginner because there is little boilerplate code for getting a simple app up and running.

For example, here is a valid "Hello, world!" web application with Flask:

from flask import Flask
app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()

The above code shows "Hello, World!" on localhost port 5000 in a web browser when run with the python app.py command and the Flask library installed.

The equivalent "Hello, World!" web application using the Django web framework would involve significantly more boilerplate code.

Flask was also written several years after Django and therefore learned from the Python community's reactions as the framework evolved. Jökull Sólberg wrote a great piece articulating to this effect in his experience switching between Flask and Django.

Flask is an implementation of the web frameworks concept. Learn how these parts fit together in the web development chapter or view all topics.

How does Flask relate to the Pallets Projects?

Flask was originally designed and developed by Armin Ronacher as an April Fool's Day joke in 2010. Despite the origin as a joke, the Flask framework became wildly popular as an alternative to Django projects with their monolithic structure and dependencies.

Flask's success created a lot of additional work in issue tickets and pull requests. Armin eventually created The Pallets Projects collection of open source code libraries after he had been managing Flask under his own GitHub account for several years. The Pallets Project now serves as the community-driven organization that handles Flask and other related Python libraries such as Lektor, Jinja and several others.

Flask tutorials

The "Hello, World!" code for Flask is just seven lines of code but learning how to build full-featured web applications with any framework takes a lot of work. These resources listed below are the best up-to-date tutorials and references for getting started.

Intermediate to advanced Flask resources

Once you move past the beginner tutorials and have created a few Flask projects you will want to learn how to use Flask extensions, deploy your code and integrate web APIs to build more extensive functionality. The following tutorials will guide you through more advanced topics and provide solid learning materials, especially when combined with the example real-world projects listed in the next section.

Open source Flask example projects

Flask's lack of standard boilerplate via a commandline interface for setting up your project structure is a double edged sword. When you get started with Flask you will have to figure out how to scale the files and modules for the code in your application. The following open source projects range from simple to complex and can give you ideas about how to working on your codebase.

Flask project templates

Flask's wide array of extension libraries comes at the cost of having a more complicated project setup. The following project templates provide a starter base that you can either use for your own applications or just learn various ways to structure your code.

Open source code for learning Flask

There are many open source projects that rely on Flask to operate. One of the best ways to learn how to use this framework is to read how other projects use it in real-world code. This section lists these code examples by class and method in Flask.

What web development topic do you want to learn next?

I've built a Python web app, now how do I deploy it?

What other Python web frameworks exist?

How can I version and store my source code?


Matt Makai 2012-2022