Answer the question
In order to leave comments, you need to log in
Loading Django content?
How can I implement automatic content loading like in twitter?
A simple model for a blog. Just to test.
Title of the article, Text of the article.
Answer the question
In order to leave comments, you need to log in
I used Django-endless-pagination in the project.
It is easily configured and integrated into the view.
Loads on scroll - like on Twitter. There is a twitter style for this
https://django-endless-pagination.readthedocs.org/...
Junga has nothing to do with it. You make an api (django-rest-framework can be used), and then track the scroll on the page with javascript. As soon as the scroll has reached the lower border, you call the api with a request for the next piece of data. After receiving the data, draw it.
I would do the following
1) 1st option
in views
from django.core import serializers
from .models import MyModel
def my_view(request):
if request.is_ajax():
x = request.GET.get('value', 5)
data = serializers.serialize('json', MyModel.objects.all()[:x] ) #тут по вкусу, можно все объекты, можно частями.
return HttpResponse(data, content_type='application/json')
else:
return render(request, 'template.html')
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
$.ajax({
type: 'GET',
url: '{% url 'app:json_view' %}', //Ссылка на вьюху
dataType: "json",
data: {'value': 10}, //Здесь можно передать данные в GET запросе, например сколько значений получить
success: function(data) {
// Ответ приходит в переменную data. Её и рендерим на страницу
}
});
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question