Reputation: 452
I'm posting this question not because I am getting some errors but because I would like to know how dajax should be used
Here is what I want to do:
I want some links on my homepage (eg. books, authors), when user clicks them, he gets a list of books/authors.
Here is what I'm doing:
When user clicks on books, I call a dajax process. Inside ajax.py:
books = Book.objects.all()
template = "{% for book in books %}"... blah blah blah
a = Template(template).render(Context(locals()))
Is this the right way to do things? Instead of writing the template in ajax.py should I open templates from some xyz.html and then render it? Any other good, clean ways to get similar tasks done?
Upvotes: 0
Views: 309
Reputation: 2128
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'.
Upvotes: 0
Reputation: 55207
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:
What you need to do is:
jQuery.get()
for jQUery)<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).Upvotes: 1