我正在尝试使用 Python 中的 Tornado API 从静态目录提供页面。这个答案与我想做的类似,但我似乎无法让它发挥作用。
我的目录结构如下所示(所有静态文件都位于名为的文件夹内web
):
我有一个像这样的网络服务器设置:
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r'/ws', WSHandler),
(r'/', IndexHandler),
]
settings = {
"debug": True,
"static_path": os.path.join(os.path.dirname(__file__), "web")
}
tornado.web.Application.__init__(self, handlers, **settings)
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(8888)
tornado.ioloop.IOLoop.instance().start()
我想这行:
"static_path": os.path.join(os.path.dirname(__file__), "web")
可能已经解决了问题,但是当我指向index.html
file:
class IndexHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
self.render('web/index.html')
它按预期提供页面,但将此错误消息打印到控制台:
WARNING:tornado.access:404 GET /css/reset.css (::1) 3.57ms
WARNING:tornado.access:404 GET /js/lib/custom-marker.js (::1) 0.96ms
WARNING:tornado.access:404 GET /js/map.js (::1) 2.08ms
WARNING:tornado.access:404 GET /js/websocket-client.js (::1) 1.56ms
WARNING:tornado.access:404 GET /css/index.css (::1) 0.89ms
在这个简约的示例中,我该如何解决我的问题?它试图指向哪里但无法找到文件?
您能提供的任何帮助将不胜感激!