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. David Baumgold // @singingwol!oy

  2. None
  3. None
  4. I don’t need to CROSS THE ALPS I just need

    a SIMPLE WEBSITE! Sheesh.
  5. None
  6. EXTENSIONS! EXTENSIONS!

  7. EXTENSIONS! EXTENSIONS! Sorry, getting ahead of myself there...

  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.
  9. Example Time!

  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:
  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!
  12. None
  13. Demo Time!

  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?
  15. EXTENSIONS! EXTENSIONS!

  16. None
  17. NEED SOMETHING WEBSCALE? or just use the database's Python module

    directly
  18. WHAT ELSE YA GOT

  19. Admin interface? Check. Flask-Admin Form management? Check.

  20. Caching? Email? OAuth? REST APIs? Markdown? I wrote that last

    one!
  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
  22. 1900 LINES of Python code 250+ PAGES of documentation Flask

    is documented just as well as Django, and that documentation is better organized
  23. None
  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
  25. ANY QUESTIONS? flask.pocoo.org David Baumgold // @singingwol!oy