Sayeed
Sayeed

Reputation: 33

HTML order list mess up with un-order list in django template

I have some data about users such as first name, last name, and email. Now I am trying to view it on the browser. But its ordering number is totally odd.

My Template Code

<!DOCTYPE html>
{% load static %}
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>User List</title>
        <link rel="stylesheet" href="{% static "css/mystyle.css" %}">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    </head>
    <body>
        <div class="container">
            <h1> Here is yours users: </h1>
            {% if user_info %}

            <ol>
                {% for user in user_info %}
                <li>{{ user.first_name }}</li>

                <ul>
                    <li>First Name: {{ user.first_name }}</li>
                    <li>Last Name: {{ user.last_name }}</li>
                    <li>Email: {{ user.email }}</li>
                </ul>
                {% endfor %}
            </ol>

            {% endif %}
        </div>
    </body>
</html>

My View Code

def userlist(request):
    user_info = UserInfo.objects.all()

    content = {
        "user_info":user_info,
    }
    print("User List")
    return render(request, "practiceApp/user-list.html", context=content)

And My Browser:

1

Upvotes: 0

Views: 344

Answers (1)

Jaydeep
Jaydeep

Reputation: 803

try this:

<ol>
    {% for user in user_info %}
    <li>{{ user.first_name }}
        <ul>
            <li>First Name: {{ user.first_name }}</li>
            <li>Last Name: {{ user.last_name }}</li>
            <li>Email: {{ user.email }}</li>
        </ul>
    </li>
    {% endfor %}
</ol>

Upvotes: 1

Related Questions