I have a question about django template

Asked 2 years ago, Updated 2 years ago, 39 views

I want to print out only those variables from the User Model below and show them to the user, so could you tell me what to do?

    {% for users in object_list %}
        <li class="user">{{ user }}</li>
    {% {% endfor %}
Wouldn't this bring all the information?

django

2022-09-20 21:48

1 Answers

#django
object_list = [[user1,id,etc],[user2,id,etc],[user3,id,etc]] #[username,id,etc]
return render(......, {"object_list":object_list}
<!-- jinja2 template -->
<table>
<tr>
    <th>username</th>
    <th>userid</th>
    <th>etc</th>
</tr>

{% {% for user in object_list %}
<tr>
    <td>{{user[0]}}</td>
    <td>{{user[1]}}</td>
    <td>{{user[2]}}</td>
</tr>
{% {% endfor %}
</table>


2022-09-20 21:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.