Recently I explored Flask and loved the simplicity and power of this Microframework. I learned Django as my first Python Web framework, but now I realise that Flask should be the first Python web framework that everyone should learn while entering into the field of Web Development with Python.
Django is a full stack framework with the batteries included approach making it easy for developers to dive it into Web Applications. But for beginners, for learning the basics of WSGI and Python web development and of dynamic web development, I do not know of any web framework that gives a better introduction to the concepts underlying it than Flask.
Starting with Flask is so simple that a hello World Web Application looks like this
# from http://flask.pocoo.org/ tutorial
from flask import Flask
app = Flask(__name__)
@app.route("/") # take note of this decorator syntax, it's a common pattern
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
With only 7 lines of code you have your Web Application running with Flask. From the above Hello World web application, a developer with no experience building Python Web applications can get Hacking immediately. You should learn flask because -
- Easy to understand
- Extensive documentation
- Built in development server and debugger
- Supports REST
- Code base small you can check the source code.
- No ORM so you can use SQLAlchemy or storm
- Uses Jinja2 templating
- Support other templates like genshi, mako
- Integrated unit testing support
- support for secure cookies (client side sessions)
- Module level integration
- 100% WSGI compliant.
- Integration with gevent, twisted, tornado is possible.
Why it should be your first Python Web Framework?
-
Flask is more Pythonic than Django because the code of flask Web Application in most cases is more explicit than the Django Web Application code. So it is easy for Python coders to pick up.
-
Beginners can learn a lot from the well documented Source Code.
-
Flask does include everything you need to start building something more complex than the above Hello World app. It integrates a templating engine (Jinja2) for you so you don't have to decide whether you would be better off using Genshi, Cheetah or Mako (though you could use).
-
The extra work at start to choose components for Flask apps yields more flexibility for developers whose use case doesn't fit a standard ORM, or who need to interoperate with different workflows or templating systems.
-
Django is a large framework which includes everything, whether you require it or not. So for smaller application Flask can give more performance. httpbin is a smaller application built with Flask.
-
Flask also scales well. Pinterest uses Flask for their API. The API Handles over 12 billion requests per day, all in Flask. More information on How Pinterest uses Flask can be found on Quora.
So, New Python developers should try Microframeworks like Flask before moving to large Frameworks like Django. You should definitely use Django after learning the small pieces of Web Applications.
Comments !