我希望通过从as_view()开始查看函数调用的进展来了解基于django类的视图。我在wsgi.py中有set_trace()函数,如下所示:
def tracefunc(frame, event, arg, indent=[0]):
if event == "call":
indent[0] += 2
#framea = sys._getframe( 0 )
print "-" * indent[0] + "> call function", frame.f_code.co_name, frame.f_code.co_filename
elif event == "return":
print "<" + "-" * indent[0], "exit function", frame.f_code.co_name
indent[0] -= 2
return tracefunc
from django.core.wsgi import get_wsgi_application
sys.settrace(tracefunc)
application = get_wsgi_application()
效果很好,我得到了这个输出:
--------> call function process_request /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py
----------> call function __init__ /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
------------> call function __init__ /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
<------------ exit function __init__
------------> call function _newname /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
<------------ exit function _newname
------------> call function _set_daemon /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
--------------> call function currentThread /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
----------------> call function __init__ /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
------------------> call function _newname /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
<------------------ exit function _newname
------------------> call function __init__ /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
--------------------> call function __init__ /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
<-------------------- exit function __init__
--------------------> call function _set_daemon /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
<-------------------- exit function _set_daemon
--------------------> call function Event /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
它打印出函数调用,但它似乎没有归结为django框架中的函数调用。有什么想法吗?我期待看到as.view()调用get()等..