Django/JavaScript: how to share code between the two? -


i've got django application makes heavy use of javascript, , want know best practice sharing code between two.

specifically, have page works both , without javascript:

  1. with javascript enabled, uses jquery autocomplete on input field, , generates table of results on autocomplete, in client-side javascript.
  2. with javascript, if type input field , submit form, same table of results returned, django view/template.

to this, i'm duplicating quite lot of code: both static html table header/footer, , code each row, generated using loop. (in pseudocode: for result in results: output '<td>result.title</td><td>result.author</td>' etc.)

how can avoid duplicating code, , instead share nicely between django , javascript?

thanks!

you can pass json client, , render client-side templating engine. example jquery templating engines


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -