Error on my .pt file on a Custom View

Hi, I've been having trouble to get this part of my custom view to work. So, my goal is to generate a python dictionary with the generateTableStats () function on my python file, which returns the dictionary I want to generate a table with. This is what I have on mine .pt file, that its not working currently.

<div id="processosContainer" class="tab autotoc-section">
                <table id="processos-statistic" tal:define="dict python:generateTableStats()">
                                <th i18n:translate="" style="width:50%; padding:5px; text-align:center;">Tipo de Processo</th>
                                <th i18n:translate="processos_estrutura" style="width:50%; padding:5px; text-align:center;">N&uacute;mero de Processos a tratar</th>

                        <tr tal:repeat="entry dict">
                                <td tal:content="entry">1</td>
                                <td tal:content="form[entry]">Outro</td>

                </table><br />

If your function generateTableStats() returns a dictionary you could iterate its items via (key, value) tuples:

<tr tal:repeat="(key, value) python:generateTableStats().items()">
    <td tal:content="key">key</td>
    <td tal:content="value">value</td>
1 Like

Seems like it should work, but when I try it, this appears:

NameError: generateTableStats

 - Expression: "python:generateTableStats().items()"
 - Filename:   ... uster/src/ip.reunioes/ip/reunioes/browser/
 - Location:   (line 197: col 35)
 - Source:     ... at="(key,value) python:generateTableStats().items()">

Is the function defined in the view? Then use:


It's defined on the src/ip.example/ip/example/browser/ file, still doesn't work!!
Thank you for the help btw!!

Now it says is an Attribute Error!

Did you reloaded your code or restarted your instance after the changes?

If you have the following in your

    <tr tal:repeat="(key, value) python:view.generateTableStats().items()">
        <td tal:content="key"></td>
        <td tal:content="value"></td>

and a function like the following in your

def generateTableStats(self):
    return {1: 2, 3: 4}

you should get a table.