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.

Flask framework learning checklist

  1. Install Flask on your local development machine.

  2. Work through the 18-part Flask tutorial listed first under "Flask resources" above.

  3. Read through Flask Extensions Registry to find out what extensions you'll need to build your project.

  4. Start coding your Flask app based on what you learned from the 18 part Flask tutorial plus open source example applications found below.

  5. Move on to the deployment section to get your initial Flask project on the web.

您接下来要学习哪些 Web 开发主题?

我已经创建了一个 Python Web 应用,那我该如何部署呢?

还有哪些其他 Python Web 框架?

如何进行版本控制和存储我的源代码?

Sign up for a monthly email with Full Stack Python tutorials. No spam ever.

Sponsored By

Rollbar logo

Fix errors in your Python code before your users see them by monitoring with Rollbar.

Learn More Python

Introduction to Ansible video course logo.

Deploy web apps with the Ansible configuration management tool.


TestDriven logo

Build microservices with Docker, Flask & React in this great course.

Full Stack Python

Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.
Updates via newsletter, Twitter & Facebook.