Question

Ok, so I am new to the Mako Templates and am using a pylons web framework.

I have my mako templates running through for loops to create some tables for me, and I was wondering if I could update the data in the for loop and have mako render that specific part of the html to easily update the webpage.

Example:

<ol>
    %for row in history:
        <li>${row.data}</li>
    %endfor
</ol>

What I would like to do in send an AJAX request to the server that returns a new set of history data, and then have mako re-render the list.

Was it helpful?

Solution

Mako renders on the server, what you want is javascript to render pieces of the page in the browser. To do that you would likely need to set up a view/controller to return the data to the client when requested, and you will need to write some javascript to call the view controller, use the data to render and then stick the result in the dom.

This is fairly general javascript/ajax stuff. The only thing it has to do with mako is that your mako template will likely have to send down some javascript along with whatever html to bootstrap the whole update process. There are a number of ways to do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top