2

I need to display all data from models in Django

I have two list one has all rows and another has all columns, what is want to do something like

{{student.username }}

I am trying to use nested loop to get all data, I know this "row.{{column}} " is wrong but did not find the solutions

 {% for row in rows %}
    <tr>
        {% for column in columns %}
          <td>{{ row.{{column}} }}</td>

       {% endfor %}
   </tr>
  {% endfor %}

can any one guide me how to use like this manner?

1 Answer 1

3

You can query the student and fetch only the required columns using values_list

Ex:

student = student.objects.values_list('column_1', 'column_2')

Then in your template

 {% for column in student %}
    <tr>
          <td>{{ column }} }}</td>
   </tr>
 {% endfor %}

MoreInfo

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.