[Answer]-Using dajax in django

0👍

Loading a template from a dedicated template file is in almost any case cleaner. A long python string with HTML in it is not very readable.

Of course you could also send your books via add_data(data,callback_function) and write a javascript callback function that populates the list which would be the Dajax way of doing what Thomas Orozco proposed.

But judging from the pagination example rendering a template file and sending it to innerHTML is ‘the right way’.

1👍

I never heard about dajax before (but it looks like the project has gone sightly inactive as the latest commit is ~10 months old), so I’ll offer advice that is not directly related to dajax.

Basically, what you need to do is to display a list that is retrieved using AJAX. That’s pretty trivial using the following tools:

  • jQuery (or another JS framework)
  • JSON

What you need to do is:

  1. Configure one of your views so that it returns a list of books (look here for the documentation)
  2. Access this view using your JS framewok of choice (jQuery.get() for jQUery)
  3. Using your JS framework, update some <ul> or <ol> on your page by adding the content that you retrieved through your get call (And you could place it in some overlay that you’d display).

Leave a comment