本文整理汇总了Python中django.views.generic.ListView.as_view方法的典型用法代码示例。如果您正苦于以下问题:Python ListView.as_view方法的具体用法?Python ListView.as_view怎么用?Python ListView.as_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.views.generic.ListView
的用法示例。
在下文中一共展示了ListView.as_view方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context_data
# 需要导入模块: from django.views.generic import ListView [as 别名]
# 或者: from django.views.generic.ListView import as_view [as 别名]
def get_context_data(self, **kwargs):
"""Get the context for this view.
Also adds the *page_template* variable in the context.
If the *page_template* is not given as a kwarg of the *as_view*
method then it is generated using app label, model name
(obviously if the list is a queryset), *self.template_name_suffix*
and *self.page_template_suffix*.
For instance, if the list is a queryset of *blog.Entry*,
the template will be ``blog/entry_list_page.html``.
"""
queryset = kwargs.pop('object_list')
page_template = kwargs.pop('page_template', None)
context_object_name = self.get_context_object_name(queryset)
context = {'object_list': queryset, 'view': self}
context.update(kwargs)
if context_object_name is not None:
context[context_object_name] = queryset
if page_template is None:
if hasattr(queryset, 'model'):
page_template = self.get_page_template(**kwargs)
else:
raise ImproperlyConfigured(
'AjaxListView requires a page_template')
context['page_template'] = self.page_template = page_template
return context
示例2: get_page_template
# 需要导入模块: from django.views.generic import ListView [as 别名]
# 或者: from django.views.generic.ListView import as_view [as 别名]
def get_page_template(self, **kwargs):
"""Return the template name used for this request.
Only called if *page_template* is not given as a kwarg of
*self.as_view*.
"""
opts = self.object_list.model._meta
return '{0}/{1}{2}{3}.html'.format(
opts.app_label,
opts.object_name.lower(),
self.template_name_suffix,
self.page_template_suffix,
)