首先安装tornado.

 

一. 在/var/www下新建文件index.py,内容如下:

import tornado.ioloop
import tornado.web
 
class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")
 
application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/index.py", MainHandler),
])
 
if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

 

二. 在命令行执行    python index.py

 

 

三. 用服务器IP+端口8888的方式访问到我们的Hello world应用了,比如127.0.0.1:8888

 

 

假如执行上述命令的时候出错,比如报:ImportError: No module named pkg_resources,那么可能你的Python安装路径不正确,可以尝试重新配置,执行:

  1. $ curl http://python-distribute.org/distribute_setup.py | python

相关文章:

  • 2021-08-14
  • 2021-05-14
  • 2021-11-27
  • 2021-11-23
  • 2021-08-14
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
  • 2021-07-08
  • 2021-07-16
  • 2021-09-21
  • 2021-09-21
相关资源
相似解决方案