Категория: Технология программирования

Кол-во просмотров: 6712

Теги: #python #django


Делаем динамическую подгрузку контента в django

Вначале ставим 'endless_pagination' и добавляем INSTALLED_APPS в settings.py

pip install django-endless-pagination

В новом app models.py создаем класс

from django.db import models
		
class Entry(models.Model):
    name = models.CharField(max_length=200, verbose_name = 'Название')

 

в views.py

 


from django.shortcuts import render, render_to_response
from core.models import *
from django.template import loader, RequestContext

from endless_pagination.decorators import page_template

def index(
        request,
        template='entry_index.html',
        page_template='entry_index_page.html'):
    context = {
        'entries': Entry.objects.all(),
        'page_template': page_template,
    }
    if request.is_ajax():
        template = page_template
    return render_to_response(
        template, context, context_instance=RequestContext(request))

 

в html entry_index.html




<html>
<title>
</title>
<body>
<h2>Entries:</h2>
{% include page_template %}
{% 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,
            paginateOnScrollChunkSize: 25,
            paginateOnScrollMargin: 5
        });
    </script>
{% endblock %}

</body>
</html>

в html entry_index_page.html




{% load endless %}

{% paginate entries %}
{% for entry in entries %}
   <div style="height: 100px">
    {{entry.name}}
    
    </div>
{% endfor %}
{% show_more %}

 

Категория: Технология программирования

Кол-во просмотров: 6712

Дата создания: 15 декабря 2015 г.

Теги: #python #django