There is class definition in django of view in view.generic.base
class View(object):
...
def as_view(cls, **initkwargs):
"""
Main entry point for a request-response process.
"""
...
def view(request, *args, **kwargs):
self = cls(**initkwargs)
if hasattr(self, 'get') and not hasattr(self, 'head'):
self.head = self.get
self.request = request
self.args = args
self.kwargs = kwargs
return self.dispatch(request, *args, **kwargs)
# take name and docstring from class
update_wrapper(view, cls, updated=())
# and possible attributes set by decorators
# like csrf_exempt from dispatch
update_wrapper(view, cls.dispatch, assigned=())
return view
It should return a function like view(request, *args, **kwargs). Notice there is a variable in 'def view', which is 'cls'.
Suppose we run:
tmp = View.as_view(), how will tmp(request, *args, **kwargs) know what is the value of cls?
THIS IS THE SIMPLIFIED SITUATION!!!!!
Say python code like this:
>>> def func1(a):
... def func2(b):
... c = a + b
... print c
... return func2
...
>>> func3 = func1(3)
>>> func3(1)
4
>>> func4 = func1(4)
>>> func3(1)
4
>>> func4(1)
5
>>> func3.a=5
>>> func3(1)
4
>>> func1.a=5
>>> func3(1)
4
What is 'a' in def of func3 actually and how did func3 get it?
Update1:
Thanks for answering. The question was not totally expressed.
I think, when we call func3 = func1(3), we have two objects in the program, code of func1, object(symbol table) of called func1(3).
My questions are:
Is there an func2() object produced by calling code func1(), or the value of func3 is just a pointer to a member of the produced func1(3) which is the instruction of func2()?
Is the a of calling func3(1) in func1(3), or the object of func2()?