I am using Django and postgres.
My views.py looks like:
def home(request):
title = Scrap.objects
return render(request, 'index.html', {'headlines': headlines})
My index.html looks like:
<div class="content"
style="background:white; color: white; font-family: Verdana;font-weight: 5;text-align: center;">
{% for headline in headlines.all reversed %}
<a href="{{ headline.url }}" target="_blank" style="color:black; font-size: medium;" />{{ headline.headlines }}</a>
<hr style="border-bottom: dotted 1px #000" />
{% endfor %}
</div>
With the above code I am getting all the rows from the databse. How can I get only "N" rows?
I have tried:
{% for headline in headlines.all[:5] reversed %}
but it throws an error.
Could not parse the remainder: '[:5]' from 'headlines.all[:5]'
headlinesvariable in the given view function. Is that a typo?