Flask is a simple and minimalist web framework written in Python. It has no database abstraction layer, form validation, or other components that a web app might require. However, Flask can be enhanced with extensions that can add application features as if they were implemented in Flask itself. It's open source under a BSD license.
Flask is easy to set up and learn. One can write a Flask app in as few as seven lines of code and extend it to thousands. Among the big companies that use Flask are LinkedIn, Pinterest, Reddit, and many more.
Flask along with Bootstrap and SQLite can be used to easily develop full-functioning web apps.
With so many frameworks out there, what's special about Flask?
Flask uses Python and is lightweight. It consumes minimum resources to get the work done. It's very easy to learn once you have a sound knowledge of Python. Flask enables rapid prototyping of your app and works very efficiently for small applications. It enables you to focus more on other jobs than being stuck with web server management.
Among the important features of Flask are a built-in web server and debugger, unit testing support, RESTful request dispatching, secure cookies, WSGI compliance, Unicode support and good documentation.
How does Flask compare to Django?
Django is a full-featured MVC framework while Flask is a micro-framework. What this means is that Django takes a "batteries-included" approach by providing many packages typically used by web apps. Flask on the other hand let's you bring in packages as required for your project.
Django is a stricter and more mature framework than Flask. Django has it's own ways of doing things, while Flask gives you all the freedom you want. For example, Django comes with an ORM but with Flask you can use any ORM of your choice.
Flask is easier to learn due to its minimalism. Beginners looking to learn a Python-based web framework can start with Flask. For simple apps, Flask is more than adequate. For complex apps or to make a polished product, you can consider migrating to Django. Because Django includes lots of useful stuff by default, it might be faster to develop complex apps. For example, Django comes with an administrator interface that can be customized. This can be useful when building a Content Management System (CMS).
As a beginner, how do I get started with Flask?
One can refer to the Flask official documentation. The User's Guide contains a quickstart guide, detailed tutorials and useful patterns in Flask.
Which websites use Flask?
There's an curated list of sites using Flask. Another list mentions big names: Red Hat, Airbnb, Netflix, Lyft, Reddit, Uber, and Samsung. Other big names include Pinterest, Twilio and LinkedIn.
What are some popular extensions used along with Flask?
These are some commonly used extensions:
- Flask-Cors: A Flask extension for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible.
- Flask-User: Customizable user authentication, user management, password recovery, and more.
- Flask-PyMongo: This bridges Flask and PyMongo. Provides some convenient helpers. PyMongo is a MongoDB driver.
- Flask-SQLAlchemy: Database abstraction layer and Object Relational Mapper (ORM) popular for Flask apps.
How do I deploy a Flask application to production?
For production, many cloud providers document procedures on how to deploy Flask on their platforms. If you wish to deploy Flask on your own,
mod_wsgiis an essential module for Apache server. If Nginx server is used, it will typically serve static files and the rest will be handed over to Gunicorn server, which becomes the WSGI entry point for the Flask application. In fact, Nginx can reverse proxy a HTTP request to any WSGI-compliant server including Apache, Gunicorn or uWSGI.
Coders from Pocco release version 0.1 of Flask. Flask is really a combination of two other projects developed at Pocco: Werkzeug (a web programming toolkit) and Jinja2 (a templating engine). It's initially called Denied–The next generation micro-web-framework.
- CS50. 2017. "CS50 Explained 2016 - Week 8 - From C to Python, Interpreted Languages." YouTube, July 18. Accessed 2019-01-19.
- CS50. 2018. "CS50: Week 7 Notes." Harvard University. Accessed 2019-01-19.
- Chandra, Varun. 2016. "Who is behind Flask and what is the story of its creation?" Quora, July 05. Accessed 2019-01-19.
- Dwyer, Gareth. 2017. "Flask vs. Django: Why Flask Might Be Better." Code Mentor, February 13. Accessed 2019-01-19.
- EDUCBA. 2018. "Django vs Flask." EDUCBA, August 13. Accessed 2019-01-19.
- Elliot, Oliver. 2015. "Notes: Making a Simple Website with Flask." June 06. Accessed 2019-01-19.
- Fatima, H. 2018. "Flask vs Django: How to Choose the Right Web Framework for Your Web App." Blog, Reseller Club, January 13. Accessed 2019-01-19.
- Flask. 2019. "Homepage." Accessed 2019-01-19.
- Flask-Cors. 2018. "Flask CORS extension." Flask-Cors, via Read The Docs, v3.0.7. Accessed 2019-01-19.
- Flask Docs. 2019. "User's Guide." Flask 1.0, Pocco. Accessed 2019-01-19.
- Flask GitHub. 2019. "pallets/flask." Flask, on GitHub, January 18. Accessed 2019-01-19.
- Flask-PyMongo. 2018. "Flask PyMongo Extension." Flask-PyMongo, via Read The Docs, v2.2.0. Accessed 2019-01-19.
- Flask-User. 2018. "Flask User Extension." Flask-User, via Read The Docs, v1.0. Accessed 2019-01-19.
- Kennedy, Patrick. 2017. "Using Docker for Flask Application Development (not just Production!)." Patrick's Software Blog, June 23. Accessed 2019-01-19.
- Lord, David. 2018. "Flask 1.0 released." Blog, The Pallets Project, April 26. Accessed 2019-01-19.
- PyPi. 2018. "Flask 1.0.2." PyPi, May 02. Accessed 2019-01-19.
- Quora. 2015. "What is the largest site created using Flask?" May 21. Accessed 2019-01-19.
- Rocha, Bruno. 2018. "rochacbruno/flask-powered." On GitHub, August 10. Accessed 2019-01-19.
- Sanders, Rachel. 2014. "Developing Flask Extensions." PyCon 2014, via YouTube, April 23. Accessed 2019-01-19.
- TechEmpower. 2018. "Web Framework Benchmarks: Round 17, Flask vs Django." TechEmpower, October 30. Accessed 2019-01-19.
- Wikipedia. 2019. "Flask (web framework)." Wikipedia, January 16. Accessed 2019-01-19.