Search code examples
pythondjangosocket.iotornadodjango-wsgi

How to turn a tornado HTTPRequest into a Django HttpRequest or WSGIRequest?


I'm writing a socket.io app using Django and TornadIO2/Tornado. In the TonradIO2 Session, I have access to Tornado's HTTPRequest objects. However, I have no access to a django request object in my event handlers in the SocketConnection class. Ideally, I'd like all the configured django middlewhere to execute on the request object before reaching my event handlers. I could call them the middlewhere explicitly, but I need to convert the HTTPRequest object to a Django HttpRequest or a Django WSGIRequest object first. Any suggestions on how to achieve this?


Solution

  • Tornado has WSGIContainer, which "makes a WSGI-compatible function runnable on Tornado’s HTTP server" and "-- intended to let other frameworks (Django, web.py, etc) run on the Tornado HTTP server and I/O loop."