Answer the question
In order to leave comments, you need to log in
Python Django, how to break all news into parts?
My view lists the top 12 news. On the news list page, I implemented the ability to load the rest of the news ajax'om. But the problem is that all the rest are displayed.
Here is an example of a view that loads news:
def lazy_ajax(request):
if request.is_ajax():
news_list = News.objects.all()[12:]
posts_html = render_to_string(template_name='news/list_ajax.html', context={'news_list': news_list})
output_data = {'posts_html': posts_html}
return JsonResponse(output_data, content_type='application/json', safe=False)
Answer the question
In order to leave comments, you need to log in
Instead of "[12:]" you need "[:12]", or rather, even "[12:12]" if you need a second page, but where is the page number parameter?
As an option, I will suggest not writing your bike - django-el-pagination
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question