当前位置: 首页>>代码示例>>Python>>正文


Python ListView.as_view方法代码示例

本文整理汇总了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 
开发者ID:mapeveri,项目名称:django-endless-pagination-vue,代码行数:33,代码来源:views.py

示例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,
        ) 
开发者ID:mapeveri,项目名称:django-endless-pagination-vue,代码行数:15,代码来源:views.py


注:本文中的django.views.generic.ListView.as_view方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。