【发布时间】:2023-10-30 20:54:01
【问题描述】:
我使用的是Ubuntu,有一个名为“webchat”的目录,在这个目录下有4个文件:webchat.py、webchat.css、webchat.html、webchat.js。
使用 Tornado 创建 HTTP 服务器时,我将根 ("/") 映射到我的 python 代码:'webchat.py',如下所示:
import os,sys
import tornado.ioloop
import tornado.web
import tornado.httpserver
#http server for webchat
class webchat(tornado.web.RequestHandler):
def get(self):
self.write("Hello, chatter! [GET]")
def post(self):
self.write("Hello, chatter! [POST]")
#create http server
Handlers = [(r"/",webchat)]
App_Settings = {"debug":True}
HTTP_Server = tornado.web.Application(Handlers,**App_Settings)
#run http server
HTTP_Server.listen(9999)
tornado.ioloop.IOLoop.instance().start()
访问http://localhost:9999 将引导我进入“网络聊天”处理程序(网络聊天类)。但是,我想使用“webchat.py”访问同一目录中的其他文件,它们是 webchat.css、webchat.html 和 webchat.js。
这个 URL 给了我 404:http://localhost:9999/webchat.html。 这个问题有什么可能的解决方案吗?
【问题讨论】:
标签: python http web chat tornado