Flask vs Django

Flask vs Django

Django is the most popular Python web framework, but there are a number of competitors. This presentation is about one of them: Flask, a microframework that has a number of advantages over Django, and is a much better choice for smaller, simpler websites.

42c77de97965d620ba0b6ae624c3ba7b?s=128

David Baumgold

November 15, 2012
Tweet

Transcript

  1. 2.
  2. 3.
  3. 4.
  4. 5.
  5. 8.

    SIMPLE Flask gives you three main things: URL Routing Templates

    Error handling & debugger mysite.com/foo goes to foo_view() powered by Jinja2! is that four things? OK, fine, four main things.
  6. 10.

    from flask import Flask app = Flask(__name__) @app.route("/") def hello():

    return "Hello World!" if __name__ == "__main__": app.run() $ pip install Flask $ python hello.py * Running on http://localhost:5000/ A full Flask application: Running it:
  7. 11.

    from flask import render_template @app.route('/hello/') @app.route('/hello/<name>') def hello(name=None): return render_template('hello.html',

    name=name) <!doctype html> <title>Hello from Flask</title> {% if name %} <h1>Hello {{ name }}!</h1> {% else %} <h1>Hello World!</h1> {% endif %} Templates!
  8. 12.
  9. 14.

    HOORAY! NOW I CAN SHOW OFF MY CAT PICTURES! But

    now I want to add a rating system and a guestbook! I CAN HAZ DATABASE?
  10. 16.
  11. 21.

    OTHER COOL THINGS (that I don't really have time to

    talk about right now) thread-local response objects session management blueprints redirect() and abort() functions real WSGI support static file optimizations unit test support message flashing THESE ARE ALL BUILT-IN
  12. 22.

    1900 LINES of Python code 250+ PAGES of documentation Flask

    is documented just as well as Django, and that documentation is better organized
  13. 23.
  14. 24.

    WRAP-UP DJANGO is LARGE and MONOLITHIC FLASK is SMALL and

    EXTENSIBLE difficult to change/replace built-in components steep learning curve little flexibility add components/complexity as necessary learn as you go write your app the way you want