使用以下示例代码:
from webob import Response
from paste.httpserver import serve
def test_iter():
from pyramid import threadlocal
yield 'current request: %s' % threadlocal.get_current_request()
def hello_world(request):
return Response(app_iter=test_iter())
if __name__ == '__main__':
from pyramid.config import Configurator
config = Configurator()
config.add_view(hello_world)
app = config.make_wsgi_app()
serve(app, host='0.0.0.0')
我收到当前请求: None。所以,threadlocal
里面不工作app_iter
?我有实际的代码,我需要访问threadlocal
远离视图的几个层,并且传递request
变量会很麻烦。