Backbone.js + Django¶
Note
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 convore.com, 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
Grove!¶
- IRC for your company
- Internal for companies
- https://grove.io
Leafy Chat¶
- Pure JavaScript
- very barebones - just JQuery
- Very dirty in that their construct HTML manually
Each submit for chat:
- handle form submit
- create new message
- display mesage in list
- POST method in AJAX
Backbone!¶
- 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://djangosnippets.org/snippets/1684
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
Router¶
- Can do overlaps of views