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:
- with javascript enabled, uses jquery autocomplete on input field, , generates table of results on autocomplete, in client-side javascript.
- 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
Post a Comment