閱讀django-endless-pagination的文檔它說你可以通過使用@page_template()裝飾器將它的Ajax分頁功能擴展到基於類的視圖。 。 我一直在嘗試使用以實施裝飾的像一小時:使用django-endless-pagination自定義基於擴展ListView的基於c的視圖
class ExtendedListView(ListView):
template_name = 'global_template.html'
@method_decorator(@page_template('path_to_updatable_content_only_template'))
def dispatch(self, *args, **kwargs):
return super(ExtendedListView, self).dispatch(*args, **kwargs)
視圖功能不輸出任何錯誤,但是當我去到另一個網頁加載目標中的「global_template」和不是在裝飾器中定義的模板。
如果有人知道這個實現是否真正起作用,並且我犯了一些錯誤,請指出,我很樂意以正確的方式使用它。
我已經設法拿出一個workarround所以如果someoene的得到了同樣的問題,有沒有標準的答案,這一點,你可以這樣做:
class ExtendedListView(ListView):
template_name='global_template_path'
'''
render_to_response ¿hack? so that i can render only the updatable DOM part template
'''
def render_to_response(self, context):
if self.request.is_ajax():
self.template_name = 'path_to_updatable_content_only_template'
return super(ExtendedListView, self).render_to_response(context)
else:
return super(ExtendedListView, self).render_to_response(context)
乾杯!
我的問題是試圖讓多個分頁工作。 – acjay 2012-09-26 22:06:20