Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

David Baumgold

November 15, 2012

Transcript

25 slides
  1. 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.
  2. 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:
  3. 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!
  4. 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?
  5. 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
  6. 1900 LINES of Python code 250+ PAGES of documentation Flask

    is documented just as well as Django, and that documentation is better organized
  7. 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

More Decks by David Baumgold

Other Decks in Technology