我正在用python tornado构建一个服务器。我的同事已经完成了前端部分。
我做了一个非常简单的测试,如下:class IndexHandler(tornado.web.RequestHandler):
def get(self):
print("this is a get request from indexhandler:\n")
print(self.request)
self.render("frontend/index.html")
if __name__ == "__main__":
tornado.options.parse_command_line()
app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
对于这个测试,浏览器得到500: Internal Server Error。因为index.html在子目录中包含一些js文件。
以下是服务器的消息:[I 170430 23:06:21 web:2063] 200 GET / (108.61.177.156) 2.56ms
[W 170430 23:06:22 web:2063] 404 GET /css/reset.css (108.61.177.156) 0.56ms
[W 170430 23:06:22 web:2063] 404 GET /css/common.css (108.61.177.156) 0.56ms
[W 170430 23:06:22 web:2063] 404 GET /css/index.css (108.61.177.156) 0.41ms
这意味着浏览器获得了index.html,但无法获取这些css文件。
所以我想我需要做这样的事情:
^{pr2}$
我试过这样做,但失败了。
另外,如果我确实需要某种正则表达式来执行此操作,我认为这是非常危险的,因为用户可以从浏览器发出这样的请求:www.mysite.com/../../someLocalFileOfServer