我对编程世界相当新,我正在尝试创建这个raspberry-pi服务器来控制互联网上的一些电子产品。但似乎我复制和编写的代码不允许网页执行java脚本。如何更改我的代码以便它还呈现java脚本?
抱歉英语不好。
Python代码:
tinymce.init({
selector: "textarea", // change this value according to your HTML
table_toolbar: "tableprops tabledelete | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol"
});
Html代码:
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.websocket
class WebServer(tornado.web.RequestHandler):
def get(self):
self.render("index.html")
class WebSocket(tornado.websocket.WebSocketHandler):
def check_origin(self, origin):
return True
def open(self):
print("Connection opened")
self.write_message("Connection opened")
def on_close(self):
print("Connection closed")
def on_message(self, message):
print("message received: " + str(message))
def main():
tornado.options.parse_command_line()
app = tornado.web.Application(handlers=[(r"/", WebServer)])
app2 = tornado.web.Application(handlers=[(r"/", WebSocket)])
server = tornado.httpserver.HTTPServer(app)
server2 = tornado.httpserver.HTTPServer(app2)
server.listen(80)
server2.listen(8000)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()
使用Javascript:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>liquoratus.pi</title>
<link href="./favicon.ico" rel="icon" type="image/x-icon" />
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1>It works</h1>
</body>
</html>
答案 0 :(得分:1)
使用StaticFileHandler
投放script.js
和favicon.ico
。
答案 1 :(得分:0)
Javascript未呈现。如果您需要动态更改html以显示从websocket推送的messeges,您可能需要通过javascript执行此操作。