Skip to content Skip to sidebar Skip to footer

What Is The Difference Between Django.views.generic.list.listview And Django.views.generic.listview In Django?

In the fourth part of the Django tutorial, it used the django.views.generic.ListView, but in Class-based views API reference, the ListView is in django.views.generic.list.ListView.

Solution 1:

Both are exactly referencing same class.You can check it by

import inspect
from django.views.generic import ListView
print(inspect.getfile(ListView))
from django.views.generic.listimport ListView
print(inspect.getfile(ListView)) 

Solution 2:

The ListView class actually lives in django/views/generic/list.py. But this is the source code of django/views/generic/__init__.py:

from django.views.generic.base import RedirectView, TemplateView, View
from django.views.generic.dates import (
    ArchiveIndexView, DateDetailView, DayArchiveView, MonthArchiveView,
    TodayArchiveView, WeekArchiveView, YearArchiveView,
)
from django.views.generic.detail import DetailView
from django.views.generic.edit import (
    CreateView, DeleteView, FormView, UpdateView,
)
from django.views.generic.listimport ListView

__all__ = [
    'View', 'TemplateView', 'RedirectView', 'ArchiveIndexView',
    'YearArchiveView', 'MonthArchiveView', 'WeekArchiveView', 'DayArchiveView',
    'TodayArchiveView', 'DateDetailView', 'DetailView', 'FormView',
    'CreateView', 'UpdateView', 'DeleteView', 'ListView', 'GenericViewError',
]


classGenericViewError(Exception):
    """A problem in a generic view."""pass

As you can see it imports all of the generic views from their respective modules. This is just a convenience which allows you to import any or all of the classes from django.views.generic without referencing the individual modules.

Post a Comment for "What Is The Difference Between Django.views.generic.list.listview And Django.views.generic.listview In Django?"