我正在使用此代码在twisted中运行django。
from django.core.handlers.wsgi import WSGIHandler
def wsgi_resource():
pool = threadpool.ThreadPool()
pool.start()
# Allow Ctrl-C to get you out cleanly:
reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
real_wsgi_app = WSGIHandler()
def my_wsgi_wrapper(environ, start_response):
environ['somekey'] = "somevalue"
return real_wsgi_app(environ, start_response)
wsgi_resource = wsgi.WSGIResource(reactor, pool, my_wsgi_wrapper)
return wsgi_resource
wsgi_root = wsgi_resource()
reactor.listenTCP(DJANGO_PORT, server.Site(wsgi_root))
在我的django视图中,如何访问密钥“somekey”?我希望传递一个我写过的特定类的实例。
答案 0 :(得分:1)
您应该可以使用request.META ['somekey']。