python - Is it okay to set instance variables in a Django class based view? -
I am trying to get Django class based ideas (CBV).
Now, I know that I can get request advice from myself. Now to say that I want to parse the parameters of these requests and want them to be stored in the classroom. Can I store it in self.xxx
? Now, obviously how classes work, it is considered directly.
But I can not exclude the flow of control by looking at the definition of see
> TemplateView ). as_view ()
refers to being an 'entry point'
I think about setting the example variable in the beginning of get_context_data ()
I do not think the right to initialize.
Can I define a __init __ ()
for my CBV? If so, can there be a threading issue or something like where many page-access probably work with a global example of my parsed data?
I know that this is a bit messy, but I'm just a bit confused of code flow in CBV.
According to According to However, you can parse the request and set the class view example attributes in a surcharge django.views.generic.base.View
the view ()
is called , it immediately calls and calls to Dispatch )
django.views.generic.base.view .__ init __
, The request object is out of the scope at this point So that you can not parse it in your own constructor overload. django.view S.generic.base.View.dispatch
, it According to the following:
class YourView (SomeView): def send (self, request, * args, ** kwargs): # request here i.e. Self.foo = request.GET.get ('foo', False) # Returns super call (see yours, self). Dispatches (requests, * args, ** kwargs)
Comments
Post a Comment