0

I'm using the following code in HTML

<tr v-for="item in rowData" >
          <th scope="row">{{ item.mail }}</th>
          <td>{{ item.date }}</td>
          <td>{{ item.adress }}</td>
          <td>{{ item.company }}</td>
          <td>{{ item.fliers }}</td>
</tr>

to add rows to the table dynamically. Everything's working fine with this code when I just open the html file, but when I use Flask and open this code on localhost, I get "jinja2.exceptions.UndefinedError: 'item' is undefined". Is there a way to make this work in Flask?

Piotr Koller
  • 599
  • 3
  • 8
  • 17

1 Answers1

-1

You're not looping over your data correctly. Currently, item does not exist as a variable in Jinja, therefore giving you the error. It has nothing to do with Vue

Try this instead:

{% for item in rowData%}
<tr>
  <th scope="row">{{ item.mail }}</th>
  <td>{{ item.date }}</td>
  <td>{{ item.adress }}</td>
  <td>{{ item.company }}</td>
  <td>{{ item.fliers }}</td>
</tr>
{% endfor %}

Also read the Jinja documentation on looping.

Joost
  • 3,609
  • 2
  • 12
  • 29
  • I don't have an error anymore, but the table is not updating in the way my original one was without Flask. – Piotr Koller Sep 07 '18 at 09:25
  • You have to give more information/code than this in order to be helped. We don't know how your table was updated in the past, nor how it is updated now, nor what the differences are, nor what you want them to be. – Joost Sep 07 '18 at 09:33
  • Of course. If the problem is not related to Vue, I'd probably ask another question to not make a mess in this thread. – Piotr Koller Sep 07 '18 at 09:38