Reputation: 5219
I've been trying to use Tornado for some part of my application. For that, I want to find out the environment information of the user, that is, the browser and OS of the user.
In pylons, I can do that but I am not getting how to do that in Tornado/
Upvotes: 1
Views: 364
Reputation: 134721
All that information is stored in the request
field of the the RequestHandler instance. It can be accessed via self.request
from within RequestHandler
methods.
It's an instance of tornado.httpserver.HTTPRequest
. Information about browser, OS etc. will be found in the headers
field.
Example:
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write(self.request.headers)
if __name__ == "__main__":
application = tornado.web.Application([
(r"/", MainHandler),
])
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Upvotes: 1