Copy the code below to your favorite text editor and save it as a .py file.
# imports import tornado.ioloop import tornado.web # write to screen class MainHandler(tornado.web.RequestHandler): def get(self): self.write('Hello World!') # r"/" == root website address application = tornado.web.Application([ (r"/", MainHandler) ]) # Start the server at port 7777 if __name__ == "__main__": PortNumber = str(7777) print(r'Server Running at http://localhost:' + PortNumber + r'/') print(r'To close press ctrl + c') application.listen(PortNumber) tornado.ioloop.IOLoop.instance().start()
You should now have a file similar to the one below.
Click the Windows button and start typing command prompt as shown below.
Please click on the icon as shown below to start the Command Prompt.
Using the Command Prompt, type python + the file location of your app.py file as shown below to start the Tornado application. Note that you need to have Python and all associated Tornado libraries installed for this to work. If you are confused, please go to my Jupyter/IPython Notebook tutorial before continuing.
If all goes well, you will see a message telling you that the server is running and the URL of the server as shown below. Yay!
Navigate to http://localhost:7777 using Chrome or any other modern browser. If you see Hello World! printed in your browser as shown below, you have officially created your very first Python powered web site. Good Job!