what is the difference between this two django imports

Viewed 55

I am new to django and I am a little bit confused what is the difference between:

from django.views.generic.detail import DetailView

and

from django.views.generic import DetailView

I've tried to read up on it in the documentation but I wasn't able to find the answer.

1 Answers

There is no difference. Both imports are pointing to the same class.

The difference is what you can also import from the package. From django.views.generic.detail are the DetailView related classes importable: SingleObjectMixin, BaseDetailView, SingleObjectTemplateResponseMixin, DetailView

The package django.views.generic acts as a wrapper for the classes that you actually use in your daily life. You can import here classes such as CreateView, DeleteView, FormView, UpdateView in one command but not the Mixin Classes that are being used internally.

As long as you don't need to use the mixins, stick with

from django.views.generic import DetailView
Related