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
Tweet

More Decks by David Baumgold

Other Decks in Technology

Transcript

  1. David Baumgold // @singingwol!oy

    View Slide

  2. View Slide

  3. View Slide

  4. I don’t need to
    CROSS THE ALPS
    I just need a
    SIMPLE WEBSITE!
    Sheesh.

    View Slide

  5. View Slide

  6. EXTENSIONS!
    EXTENSIONS!

    View Slide

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

    View Slide

  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.

    View Slide

  9. Example Time!

    View Slide

  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:

    View Slide

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

    Hello from Flask
    {% if name %}
    Hello {{ name }}!
    {% else %}
    Hello World!
    {% endif %}
    Templates!

    View Slide

  12. View Slide

  13. Demo Time!

    View Slide

  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?

    View Slide

  15. EXTENSIONS!
    EXTENSIONS!

    View Slide

  16. View Slide

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

    View Slide

  18. WHAT ELSE
    YA GOT

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  22. 1900 LINES
    of Python code
    250+ PAGES
    of documentation
    Flask is documented just as well as Django,
    and that documentation is better organized

    View Slide

  23. View Slide

  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

    View Slide

  25. ANY QUESTIONS?
    flask.pocoo.org
    David Baumgold // @singingwol!oy

    View Slide