4π
β
In class based generic views, any request should have itβs own instance of the MyView
class.
Here is our urls.py
:
from foo.views import AboutView
....
(r'^about/', AboutView.as_view()),
urls.py
is imported once per django thread. This means that calling as_view
does not create an instance of AboutView
.
When a request is processed by the urlconf, the view()
method is called and only then an AboutView
instance is created, passing and populating it with all the relevant data needed for this particular request.
Using :
(r'^about/', AboutView().dispatch), #WRONG!!!!
will cause all requests to share the same instance of the view, including possible properties that should not be re used by different requests.
π€Udi
Source:stackexchange.com