-1

I have list in a list that look like this :

clientList = [['Client 1', 'Yes', 'No', 'Yes', 'Yes'], ['Client 2', 'No', 'No', 'Yes', 'Yes'], ['Client 3', 'Yes', 'Yes', 'Yes', 'Yes']]

I need to call the list in the template dynamically as below

<table>
  <tr>
    {% for c in clientList %}
    <td>{{c}}</td>
    {% endfor %}
  <tr>
<table>

But it doesn't work because it looks like this:

image of output

And I also can't loop it using the method {{c.0}}, {{c.1}}, {{c.3}}, {{c.4}} because the list will change according to how many clients are selected. So I need to loop it dynamically.

I tried to use the method in this link but it didn't work because I kept getting the error list indices must be integers or slices, not str

Is there any way I can do this ?

Neuron
  • 5,141
  • 5
  • 38
  • 59
qsejj
  • 3
  • 1
  • What is your expected output? Also why can't you use the `{{ c.0 }}` syntax? It has nothing to do with the number of clients. – Selcuk Aug 16 '21 at 02:58
  • @Selcuk He can't use `{{ c.0 }}` because he doesn't know how many elements `c` has. Some might have 3, some might have 4, etc. – John Gordon Aug 16 '21 at 03:32
  • @JohnGordon Well, you might be right but that's not how I originally read the question: _"the list will change according to how many client are selected"_. – Selcuk Aug 16 '21 at 04:21

1 Answers1

0

Please try the below. as you said, theres's a list inside a list. You did loop through the first list but forgot the second one.

    <table>
     <tr>
       {% for c in clientList %}
       {% for a in c %}
       <td>{{a}}</td>
       {% endfor %}
       {% endfor %}
     <tr>
    <table>
Brian Destura
  • 11,487
  • 3
  • 18
  • 34
Abul Ahmed
  • 26
  • 1