2013-03-17 57 views
2

我試圖在我的項目上實現django-endless分頁。簡單的分頁工作(「顯示更多」),但Twitter風格(基於AJAX)給我麻煩。django-endless-pagination twitter -style

這是我的看法:

@page_template('userena/profil_page.html') # just add this decorator 
def public_details(request, username=None, 
    template = 'userena/profil.html', extra_context=None): 
    user = get_object_or_404(get_user_model(), username__iexact=username) 

    userObjekat = User.objects.get(username=username) 
    user_profil = userObjekat.get_profile() 

    context = { 
     'projekti': user_profil.projekat_set.all(), 
    } 
    if extra_context is not None: 
     context.update(extra_context) 

    return userena_views.profile_detail(request, extra_context=context, username=username, template_name='userena/profil.html') 

至於建議,我的模板被細分爲2個,「主」之一,AJAX之一。這是主模板,它加載_page模板的一部分:

</li> 
{% include page_template %} 
</li> 

和_page Template獲取包括 - 我能看到的內容。

_page模板:

{% load endless %} 
<li id="projektiTab"> 
    <div class="ten columns"> 
    <ul class="accordion"> 
    {% paginate projekti %} 
    {% for projekat in projekti %} 
    <li>       
     <div class="title"> 
      <h6> {{ projekat.naziv }}</h6> 
     </div> 
     <div class="content"> 
      <p>{{ projekat.opis }}</p> 
     </div> 
    </li> 
    {% endfor %} 
    {% show_more %} 
<li> 
</div> 
</li> 

的Javascript得到還裝載(STATIC_URL工作),並在頁面的源代碼我使用:

<script src="/static/js/endless-pagination.js"></script> 
     <script> 
     $.endlessPaginate({ 
      paginateOnScroll: true, 
      paginateOnScrollChunkSize: 5 
     }); 
     </script> 

這一切後,分頁通過滾動不工作。我究竟做錯了什麼?

回答

2

我當然有一些「小」的錯誤,這似乎不重要,但它們不是。

其持有page_template主模板,或父模板,應該包含這樣的事情:

<div class="endless_page_template"> 
    {% include page_template %} 

    {% block js %} 
    {{ block.super }} 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script src="{{ STATIC_URL }}js/endless-pagination.js"></script> 
    <script>$.endlessPaginate();</script> 
    {% endblock %} 
</div> 

因此,它必須與特定類,這是我昨天忽略了一個DIV。

page_template看起來是這樣的:

{% load endless %} 

{% paginate projekti %} 
{% for projekat in projekti %} 
    {{ projekat.name }} 
{% endfor %} 
{% show_pages %} 

這當然可以與一些HTML(在我的情況Zurb基金會的手風琴元素)來美化。最後但並非最不重要 - 觀點:

@page_template('userena/profil_strana.html') # name of the page_template 
def public_details(request, username=None, 
    template = 'userena/profil.html', extra_context=None): 

    userObjekat = User.objects.get(username=username) # getting user object 
    user_profil = userObjekat.get_profile() # getting user's profile 
    context = { 
     'projekti': user_profil.projekat_set.all(), # and a list of objects to iterate thru 
    } 
    if extra_context is not None: 
     context.update(extra_context) 

    return userena_views.profile_detail(request, extra_context=context, username=username, template_name=template) 

它的工作原理。