0
所以我試圖在我的項目中實現Twitter風格的分頁與ajax,但是當我點擊show_more時,它會出現問題。它只是改變爲標籤「加載」,並沒有顯示任何新條目。 views.py無盡的分頁卡住show_more
def view_dates(request, check, template = 'dates.html',page_template = 'dates_table.html'):
check = Check.objects.get(id = check)
dates = Date.objects.filter(check_id = check).order_by('-date').select_related('check').annotate(status = Min('result__status'))
context = {
'dates': dates,
'check': check,
'page_template': page_template}
if request.is_ajax():
template = page_template
return render_to_response(template, context, context_instance=RequestContext(request))
dates.html
{% paginate 16 dates %}
<br>
<table class = 'table table-hover'>
<tr>
<td>Date</td>
<td>Status</td>
<td></td>
</tr>
<div class="endless_page_template">
{% include page_template %}
</div>
</table>
{% show_more %}
</body>
{% block js %}
{{ block.super }}
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://yourjavascript.com/337923491/endless.js" charset="utf-8"></script>
<script type="text/javascript" src="http://yourjavascript.com/151379951/endless-pagination.js"></script>
<script>
$.endlessPaginate({paginateOnScroll: true,
endless_on_scroll_margin : 10,
paginateOnScrollChunkSize: 5
});</script>
{% endblock %}
page_template - dates_table.html
{% load date_extras %}
{% block table %}
{% for date in dates %}
<tr>
<td>
<button type="button" class="btn btn-link" onclick="location.href='/checks/{{ date.check_id }}/{{ date.id }}/results/'">
{{ date.date|format }}
</button>
</td>
<td>
{% if date.status == True %}
<span class="glyphicon glyphicon-ok"></span>
{% else %}
<span class="glyphicon glyphicon-remove"></span>
{% endif %}
</td>
<td><a href='/checks/{{ date.check_id }}/{{ date.id }}/delete/'><span class="glyphicon glyphicon-trash"></span></a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
什麼應該是什麼問題?
也許你有一個異常時,無休止的分頁實際執行一個Ajax請求。檢查日誌或控制檯。我能看到的一個問題是,如果'request.is_ajax'你應該返回響應爲json。 –
你知道,當我刪除request.is_ajax語句時,ajax實現開始工作,但它加載了多個可滾動的dates.html頁面。 因此,看起來我在頁面模板 – Sykes
有問題是的,可能只是嘗試直接渲染頁面模板,例如在視圖調用中更改'template ='dates_table.html'',它會發現錯誤。 –