📜  count gabarit django - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:51.786000             🧑  作者: Mango

代码示例2
#views.py
#You should instead pass places_count via the context to the template:
def places(request):
    places = Places.objects.order_by('-published_date')[:10]
    places_count = Places.objects.count()
    return render(
        request, 'templates/places.html', {'places':places, 'places_count': places_count}
    )
#in your templatee

Places {{ places_count }}