对象列表Django列表视图
什么是对象列表? 它是遗传的吗? 你必须定义它吗?我希望这些文档能够有清晰的解释,而不是一个模块一个模块地浏览,却仍然找不到,谢谢大家,在《继承》中你可以看到这一点对象列表Django列表视图,django,Django,什么是对象列表? 它是遗传的吗? 你必须定义它吗?我希望这些文档能够有清晰的解释,而不是一个模块一个模块地浏览,却仍然找不到,谢谢大家,在《继承》中你可以看到这一点 class django.views.generic.list.ListView¶ A page representing a list of objects. While this view is executing, self.object_list will contain the list of objects (usu
class django.views.generic.list.ListView¶
A page representing a list of objects.
While this view is executing, self.object_list will contain the list of objects
(usually, but not necessarily a queryset) that the view is operating upon.
Example views.py:
from django.utils import timezone
from django.views.generic.list import ListView
from articles.models import Article
class ArticleListView(ListView):
model = Article
paginate_by = 100 # if pagination is desired
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['now'] = timezone.now()
return context
如果深入了解BaseListView继承了哪些内容,您将确切地看到get_queryset是如何为ListView实现的
从了解流程、方法和属性开始,逐步了解您可以看到的其他视图
class django.views.generic.list.ListView¶
A page representing a list of objects.
While this view is executing, self.object_list will contain the list of objects
(usually, but not necessarily a queryset) that the view is operating upon.
Example views.py:
from django.utils import timezone
from django.views.generic.list import ListView
from articles.models import Article
class ArticleListView(ListView):
model = Article
paginate_by = 100 # if pagination is desired
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['now'] = timezone.now()
return context
如果深入了解BaseListView继承了哪些内容,您将确切地看到get_queryset是如何为ListView实现的
从了解流程、方法和属性开始,逐步了解其他视图