Backbone.js + Django


I’m having trouble keeping up when it comes to writing JavaScript fast. :P

  • Question: Why not JQuery templates?
  • Question: Best Practices?
  • by Leah Culver
  • Works at, a YC Combinator funded project
  • LeafyChat - Django Dash 2009
  • web-based IRC client

Convore issue?

  • Who is supposed to use it?
  • Internal company stuff
  • What kind of discussions


Leafy Chat

  • Pure JavaScript
  • very barebones - just JQuery
  • Very dirty in that their construct HTML manually

Each submit for chat:

  1. handle form submit
  2. create new message
  3. display mesage in list
  4. POST method in AJAX


  • MVC style of programming for AJAX/JavaScript
  • More like DJango: MTV
// models are easy!
window.Message = Backbone.model.extend({
    model: Message,

    initialize: function(){
        this.model.bind('add', this.addMessage)
        // TODO



// form submits
submitForm: function(){


Handlebars templates

  • handlebars.js templates
  • looks like Django/Jinja2 templates
  • See include_raw template tag as per htto://

Addition Goodies about backbone.js

  • Uses similiar routing to Django

  • Handy code snippet by Leah for Django CBV usage:

  • Event based asynchronous

    • One thing can fire off multiple request
    • So if I am watching and someone else posts then I see the results


  • Can do overlaps of views