1

So for a project i'm working on, i want to return data into a table. It is basically this query that gets the data:

search_result = sp.search(q=search_query, limit=20)

        response = []
        for i, t in enumerate(search_result['tracks']['items']):
            response += i, t['name']

And in the template I try to display the data from the response as follow

<tbody>
    {% for data in response %}
  <tr>
    <td>{{data}}</td>
  </tr>
  {% endfor %}
</tbody>

Only the data is now being display in a wrong way:

------------------------
0
------------------------
[data here]
------------------------
1
------------------------
[data here]

I just started programming in python/django, so I am not sure how to display it in a way that the number and data are on the same row, or if I can display it without the integer

1 Answer 1

2

There's no need that loop in the view. The whole thing should be done in the template. Just send the tracks data directly to the template, and use forloop.counter:

{% for data in tracks %}
  <tr>
    <td>{{ forloop.counter }}</td> <td>{{ data }}</td>
  </tr>
{% endfor %}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.