我寫了一個(gè)頁(yè)面,引用了bootstrap中的文件,剛開(kāi)始我的目錄結(jié)構(gòu)是這樣的:bootstrapcssbootstrap.cssjsbootstrap.jsimgtornadoexample.html目錄中的文件并沒(méi)有全部列出來(lái)。example.html中引用bootstrap的代碼如下:我的hello.py代碼如下:importtornado.ioloopimporttornado.webimportosclassMainHandler(tornado.web.RequestHandler):defget(self):print"here"self.render("example.html")application=tornado.web.Application([(r"/",MainHandler)])if__name__=="__main__":application.listen(8888)tornado.ioloop.IOLoop.instance().start()運(yùn)行的時(shí)候發(fā)現(xiàn)bootstrap的樣式表和js效果全部沒(méi)有,在firebug下面看到很多下面這樣的錯(cuò)誤:"NetworkError:404NotFound-http://localhost:8888/bootstrap/js/bootstrap.js"然后,我看了tornado的文檔,做了如下改動(dòng):在tornado目錄下面新建一個(gè)static目錄,把bootstrap放進(jìn)去,目錄結(jié)構(gòu)如下:tornadostaticbootstrapcssjsimghello.pyexample.html把example.html對(duì)bootstrap文件的引用改成下面這樣:hello.py修改部分如下:settings={"static_path":os.path.join(os.path.dirname(__file__),"static")}#配置靜態(tài)文件路徑application=tornado.web.Application([(r"/",MainHandler),],**settings)再次執(zhí)行發(fā)現(xiàn)結(jié)果正常。我很納悶,tornado一定要配置static_path嗎?我之前的錯(cuò)誤是在哪里?而且我把bootstrap目錄放回最初的目錄,然后這樣配置settings:settings={"static_path":os.path.join(os.path.dirname(__file__),"../bootstrap")}example.html還是最初那樣,這樣修改還是錯(cuò)誤,求教到底是哪里的問(wèn)題?
tornado 靜態(tài)文件的路徑錯(cuò)誤
慕斯王
2019-04-07 09:38:42