import listview django code example
Example 1: django listview
class YourView(ListView):
model = YourModel
paginate_by = your_pagination_number
context_object_name = 'your_model_in_plural'
template_name = 'your_list.html'
Example 2: django display view library
from django.views.generic.detail import DetailView
Example 3: views.MainView.as_view(), name='all'
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
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['now'] = timezone.now()
return context
Example 4: views.MainView.as_view(), name='all'
from django.urls import path
from article.views import ArticleDetailView
urlpatterns = [
path('<slug:slug>/', ArticleDetailView.as_view(), name='article-detail'),
]