Question: I need help to use TORNADO in PYTHON. I have written a small code, but suppose, after making this a simple page, I want to

I need help to use TORNADO in PYTHON.

I have written a small code, but suppose, after making this a simple page, I want to count up every single time someone requests to visit the page. Every time the page is refreshed will give the correct number, it shouldn't need to be dynamically. What should I add? Kindly write comment to explain also. And If I have to make new file to do that then please say in details. I am new in this area.

I have copied the program I wrote-

from tornado import httpserver from tornado import gen from tornado.ioloop import IOLoop import tornado.web

class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello World")

class HtmlHandler(tornado.web.RequestHandler): def initialize(self, ref_object = None): self.ref_object = ref_object def get(self): self.render('firstPage.html')

class App(tornado.web.Application):

def __init__(self): handlers = [ (r"/?", MainHandler), (r"/html/?", HtmlHandler) ] tornado.web.Application.__init__(self, handlers)

def main(): a = App() a.listen(8888) IOLoop.instance().start()

if __name__ == '__main__': main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!