ralpher01
ralpher01

Reputation: 141

Python 3 Tornado website

I am trying to create a simple local website using Tornado. When I run this and go to http://localhost:8888, I get the following error: This site can’t be reached localhost refused to connect. I am still a beginner with python so any help would be much appreciated. My code is shown below.

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("<!DOCTYPE html><head><title>" + "Hello world</title></head>" + "<body>Hello World</body>")

    if __name__ == "__main__":
        application = tornado.web.Application([(r"/", MainHandler),
                                               ],)
        application.listen(8888)
        tornado.ioloop.IOLOOP.instance().start()

Upvotes: 1

Views: 311

Answers (1)

falsetru
falsetru

Reputation: 369444

IOLOOP should be IOLoop:

tornado.ioloop.IOLoop.instance().start()
#              ^^^^^


UPDATE You need to indent correctly the code. Especially if __name__ == "__main__": part, that part should be outside of class .. definition:

if __name__ == "__main__":  # <----
    application = tornado.web.Application([(r"/", MainHandler),
                                           ],)
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

Upvotes: 1

Related Questions