[Django]-What is the difference between django.views.generic.list.ListView and django.views.generic.ListView in Django?

3👍

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.list import ListView
print(inspect.getfile(ListView)) 

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.list import ListView

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


class GenericViewError(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.

Leave a comment