Wednesday, May 16, 2012

Thread safety with view arguments in class based views

According to the docs on the generic class based views:

Each request served by a View has an independent state; therefore, it is safe to store state variables on the instance (i.e., self.foo = 3 is a thread-safe operation).

and
Any argument passed into as_view() will be assigned onto the instance that is used to service a request.  
but then right after that, it says: 

Arguments passed to a view are shared between every instance of a view. This means that you shoudn't use a list, dictionary, or any other variable object as an argument to a view. If you did, the actions of one user visiting your view could have an effect on subsequent users visiting the same view.


I'm confused then.  Under what conditions do arguments passed to ClassView.as_view() become bound to that instance vs when do tehy get bound to the class as a whole (between requests)?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/0TLv7GnLL2cJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate