Javascript Tornado呈现的index.html正文为空
我正在使用Tornado进行分层,并尝试在启动时使用静态js脚本呈现index.html模板 这是我的main.py:Javascript Tornado呈现的index.html正文为空,javascript,python,html,tornado,Javascript,Python,Html,Tornado,我正在使用Tornado进行分层,并尝试在启动时使用静态js脚本呈现index.html模板 这是我的main.py: import tornado.ioloop import tornado.web import tornado.websocket import signal import logging from tornado.options import options import Settings is_closing = False def signal_handler(si
import tornado.ioloop
import tornado.web
import tornado.websocket
import signal
import logging
from tornado.options import options
import Settings
is_closing = False
def signal_handler(signum, frame):
global is_closing
logging.info('exiting...')
is_closing = True
def try_exit():
global is_closing
if is_closing:
# clean up here
tornado.ioloop.IOLoop.instance().stop()
logging.info('exit success')
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("index.html", title = "Home")
class Application(tornado.web.Application):
def __init__(self):
settings = {
"template_path": Settings.TEMPLATE_PATH,
"static_path": Settings.STATIC_PATH,
}
handlers = [
(r"/", MainHandler),
#(r"/index", tornado.web.StaticFileHandler, dict(path=settings["template_path"]+"/index.html"))
]
tornado.web.Application.__init__(self, handlers, **settings)
if __name__ == "__main__":
application = Application()
tornado.options.parse_command_line()
signal.signal(signal.SIGINT, signal_handler)
application.listen(8888)
tornado.ioloop.PeriodicCallback(try_exit, 100).start()
tornado.ioloop.IOLoop.instance().start()
这是我的index.html:
<html>
<head>
<title>{{ title }}</title>
<script src="{{ static_url("js/main.js") }}" type="javascript"/>
</head>
<body>
<h1>This is currently touching your sockets</h1>
{{ title }}
</body>
</html>
当我请求“/”时,我得到一个空白页。但是,标题设置正确,js嵌入正确。基本上整个头部都存在,但整个身体是空的
更重要的是,html正确地到达了客户端,我可以在chrome networking开发工具中看到,在服务器发送的html中,主体是存在的,但之后不知何故没有呈现出来
发生了什么事?main.js中有什么内容?不带async属性的从加载的Javascript将在主体显示之前被解析和执行。我还认为main.js中的某些内容可能会导致此问题。你需要向我们展示整个画面。