I'm attempting to use django-endless-pagination in my project, but the results don't appear to be using AJAX. My goal is twitter-like pagination, where you scroll down and more elements are listed without refreshing the page.
This is my view code:
@page_template('ajax_test_page.htm')
def ajax_test(request, template='ajax_test.htm', extra_context=None):
context = { 'dreams': Dream.objects.all() }
if extra_context is not None:
context.update(extra_context)
return render_to_response(template, context, context_instance=RequestContext(request))
This is ajax_test.html:
<!DOCTYPE html>
{% block js %}
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="{{ STATIC_URL }}endless_pagination/js/endless-pagination.js"></script>
<script>$.endlessPaginate({
paginateOnScroll: true,
paginateOnScrollMargin: 20
});
</script>
{% endblock %}
<h2>Ajax Test</h2>
{% include page_template %}
And this is ajax_test_page.htm:
{% load endless %}
{% paginate dreams %}
<div>
{% for dream in dreams %}
Dream title: {{ dream.title }}<br>
{% endfor %}
</div>
{% show_more %}
The result I get is no different than using Django's built-in paginator. I see a list of ten entries and a "more" link; when I click the "more" link, I'm taken to "/ajax_test/?page=2", which involves refreshing the entire page (rather than appending a new set of entries) and is not what I want to do. Scrolling to the bottom also has no effect despite having set the flags to do so.
I've even completely disabled javascript in the browser and it didn't change anything, signifying that the javascript is just going completely ignored for some reason. Same results in Chrome and Firefox.
What am I doing wrong?
I ran into the same problem. You have to wrap the call to
endlessPaginate
withWe'll fix the documentation asap
I'm not sure but instead of
try using this form
Don't forget to run a
python manage.py collectstatic
before relaunching your server.