How do I auto increment my results in a page?

I made this table but I can't figure out how to do the numbering. I want a top 10 list and I get all the data from a database. I essentially want to make it show '1' and the next '2' and the next '3' and so forth. How would I able to do this?


def home(request): straatData = data.objects.all()[:10]

count = data.objects.count()
numbers = []

for dataCount in range(1, count + 1):
numbers.append(dataCount)

context = {
‘data’: straatData,
‘count’: numbers,
}

return render(request, ‘home.html’, context)

I need to get the top numbers to show 1,2,3,4… as many as the results. But I don’t know how to do it

#python #django

What is GEEK

Buddha Community

Alfie Mellor

1548813656

You don’t need to set a context variable for that. You can use forloop.counter in your template code.

{% for item in data %}
<tr>
   <td> {{ foorlop.counter }} </td>
   <td> {{ item }} </td>
</tr>
{% endfor %}

If you want to start counting at 0, use forloop.counter0

Perhaps you should be using jinja to render the table in a loop?

In your html:

{% for num in count %}
<tr>
   <td> {{ num }} </td>
   <td> {{ data[num][0] }} </td>
   <td> {{ data[num][1] }} </td>
   <!-- Im not sure how your data is formatted! -->
</tr>
{% endfor %}

Without seeing your html it’s hard to know how you’re currently rendering the table.

Rusty  Bernier

Rusty Bernier

1597321578

Razor Pages vs MVC - Which one is better for your project?

In this article, I will discuss Razor Pages vs MVC on how to choose in ASP.NET Core web applications. You will also see which type of web application is well suited for your project or requirement by looking at benefits and code comparison.

#.net core #.net core razor pages vs mvc #mvc vs razor pages #razor pages vs mvc #razor pages vs mvc how to choose

Indian Matka

1617179232

Satta Matka Results | Indian Satta Matka

Matka results is the world’s leading platform in Online gamling market which gives satta matka results online with all matka tricks and tips to earn some amount of money . Play Now

#indian satta #satta matka #satta matka result #fix matka result #fix matka number #all matka result

Paresh Sagar

1581940975

What Is A Single-Page Application?

Single page web apps are an ideal choice when thinking about future web development. This architecture is a perfect choice for social networks stuff, SaaS platforms, or some close communities where SEO doesn’t matter.

#what is a single page application #single page application #single page application development

How do I auto increment my results in a page?

I made this table but I can't figure out how to do the numbering. I want a top 10 list and I get all the data from a database. I essentially want to make it show '1' and the next '2' and the next '3' and so forth. How would I able to do this?


def home(request): straatData = data.objects.all()[:10]

count = data.objects.count()
numbers = []

for dataCount in range(1, count + 1):
numbers.append(dataCount)

context = {
‘data’: straatData,
‘count’: numbers,
}

return render(request, ‘home.html’, context)

I need to get the top numbers to show 1,2,3,4… as many as the results. But I don’t know how to do it

#python #django