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.
Ancestors (MRO)
This view inherits methods and attributes from the following views:
django.views.generic.list.MultipleObjectTemplateResponseMixin
django.views.generic.base.TemplateResponseMixin
django.views.generic.list.BaseListView
django.views.generic.list.MultipleObjectMixin
django.views.generic.base.View
Method Flowchart
dispatch()
http_method_not_allowed()
get_template_names()
get_queryset()
get_context_object_name()
get_context_data()
get()
render_to_response()
Example views.py:
from django.views.generic.list import ListView from django.utils import timezone from articles.models import Article class ArticleListView(ListView): model = Article def get_context_data(self, **kwargs): context = super(ArticleListView, self).get_context_data(**kwargs) context['now'] = timezone.now() return context
Example myapp/urls.py:
from django.conf.urls import url from article.views import ArticleListView urlpatterns = [ url(r'^$', ArticleListView.as_view(), name='article-list'), ]
Example myapp/article_list.html:
<h1>Articles</h1> <ul> {% for article in object_list %} <li>{{ article.pub_date|date }} - {{ article.headline }}</li> {% empty %} <li>No articles yet.</li> {% endfor %} </ul>
Please login to continue.