Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango and client-side javascript templates
    text
    copied!<h2>Intro</h2> <p>I'm currently writing a very standard Django based app (basically a fancy CRM/contact list sort of thing). It's sort of working, but as I keep trying to improve the interface with more and more AJAXy UI code (using jQuery) it's starting to get to be a real pain to work with. I'm getting long blocks of fragile jQuery event handlers which parse the DOM, push changes back to the server, get some JSON back, and try and update the DOM based on that.</p> <p>I feel like, at a minimum, I probably want to add some client-side templates into the mix. Alternatively, I could try and switch to a JS framework, and just use my Django app as a database abstraction layer. Or even though I know and love Python, I could abandon the Django app, and try and go with a JS/Node.js solution or something.</p> <p>Has anyone else been in this situation? How did you solve it? </p> <h2>Design goals</h2> <ol> <li>DRY: I don't want to have to replicate my models or my templates (or at least, any more than necessary).</li> <li>I want visitors landing on a page to get the results rendereed server-side.</li> <li>As visitors click on things, I'd like to handle that via client-side templates and rendering, and keep the server updated via AJAX calls to a REST interface.</li> </ol> <p>So...how do I do this? I've collected links to a few frameworks and template systems. In no particular order:</p> <h3><a href="http://akdubya.github.com/dustjs/">dust.js</a>:</h3> <p>This is apparently <a href="http://engineering.linkedin.com/frontend/leaving-jsps-dust-moving-linkedin-dustjs-client-side-templates">being used by LinkedIn</a> to solve a similar problem. It uses Node.js on the server side which is not ideal (I've never used Node) but at least it's not JVM based. It also appears to be dormant on github - I've found mailing lists where people have been wondering where the maintainer went. It does sound pretty good - the blog post from LinkedIn does a good job selling the technology, especially the ability to compile it. But it appears to JUST be templating. Is that enough for what I want?</p> <h3><a href="http://mustache.github.com/">Mustache</a>:</h3> <p>This option has both Python and JS implementations, and seems popular...but I can't find anyone who seems to be using Mustache templates with Django. Is that 'cause it's too easy to deserve a blog post, or is it impossible or otherwise inadvisable? It's also pretty limited; at a minimum I'd probably need to turn to some sort of MVC JS framework, right?</p> <h3>Backbone, Spine, KnockoutJS, EmberJS, JavascriptMVC, etc:</h3> <p>There's so <em>many</em> frameworks it's kind of daunting. All of them seem perfectly good at first glance. It also seems like I'd need to rewrite a LOT of my app if I went this route, and I'd really would like to find someone who has actually done something like this already. Also, it'd be nice if there was a clear choice for someone coming from Django as a background; I don't want to have to learn a half dozen different frameworks to evaluate them.</p> <h3><a href="http://derbyjs.com/">DerbyJS</a></h3> <p>This looks interesting as it handles both the client and server sides in one package, but a bit immature. They warn against using it in production, and if I understand the docs it doesn't yet support any form of persistence, which is...limiting. I get the feeling that if it was finished it would be <em>perfect</em> for what I want though...</p> <h2>So....</h2> <p>So, uh...now what? Has anyone used any of these tools to try and add client-side rendering to a Django webapp? How did it go?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload