# Flask

## Summary


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.

## Discussion

### 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. 

Week 7 of Harvard's CS50 course is useful if you want a proper classroom type tutoring with assignments. Flask Tutorial Playlist by Corey Schafer is also a good starting point.

Use `pip` to install Flask: `pip install -U 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?

Flask can be used to implement an Model-View-Controller (MVC) pattern of web framework: Flask (controller), SQLite (model), Bootstrap (view). Jinja2 is popular for rendering HTML templates and is part of the view. Flask can be used with front-end frameworks such as VueJS but you would have to learn JavaScript.

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?

Flask comes with a simple built-in server. This runs on the default port 5000. This is commonly used for development but not recommended for production because it doesn't scale well. 

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_wsgi` is 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. 

## Milestones

2004

Pocco is formed as an international group of Python Enthusiasts. 

Apr  
2010

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.

Sep  
2016

Harvard's popular *CS50: Introduction to Computer Science* course incorporates Flask to teach web development, thus shifting focus from PHP to Python. It becomes available on edX as CS50x from 2017.

Apr  
2018

Flask 1.0 is launched. Python versions 2.7 and 3.3 are no longer supported. Thus, Flask requires Python 2.7, Python 3.4 and above, or PyPy. 

May  
2018

Flask 1.0.2 is released.