Tornado 和 JavaScript 库的问题
我正在尝试使用 Tornado Web 服务器编写一个简单的 Python Web 应用程序,但在使用我需要的 JavaScript 库时遇到问题。我想使用 Protovis JavaScript 绘图库,因此我将以下“Hello World”代码片段添加到我的 template.html 中:
<script type="text/javascript" src="/protovis-d3.2.js"></script>
<script type="text/javascript+protovis">
new pv.Panel()
.width(150)
.height(150)
.anchor("center")
.add(pv.Label)
.text("Hello, world!")
.root.render();
</script>
但是,每当我运行网络服务器并尝试访问该页面时,我都会在控制台上收到以下错误:
WARNING:root:404 GET /protovis-d3.2.js (127.0.0.1) 0.46ms
protovis.js 文件与我的 server.py 文件位于同一目录中,并且其所有权限都设置正确。当我尝试 src 和 JavaScript 文件时,我遇到了同样的错误,所以我知道 protovis.js 文件没有问题,但 Tornado 服务器的路由有问题。
有谁知道我如何正确src这个JavaScript代码,谢谢。
I'm trying to write a simple python web application using the Tornado web server and am having trouble using the JavaScript libraries I need. I wanted to use the Protovis JavaScript plotting library, so I added the following 'Hello World' code snippet to my template.html:
<script type="text/javascript" src="/protovis-d3.2.js"></script>
<script type="text/javascript+protovis">
new pv.Panel()
.width(150)
.height(150)
.anchor("center")
.add(pv.Label)
.text("Hello, world!")
.root.render();
</script>
Whenever I run the webserver, however, and try accessing the page, I get the following error at the console:
WARNING:root:404 GET /protovis-d3.2.js (127.0.0.1) 0.46ms
The protovis.js file is in the same directory as my server.py file, and all its permissions are set correctly. I get the same error when trying to src and JavaScript file so I know there isn't a problem with the protovis.js file, but something with the Tornado server's routing.
Does anyone know how I can properly src this JavaScript code, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该阅读有关 静态文件。
具体来说,标准方法是:
在应用程序的根目录中创建一个“静态”目录
将以下内容添加到您的应用程序设置中:
"static_path": os.path.join(os.path.dirname(file), "static")
将protovis-d3.2.js放入静态目录
You should read the documentation about static files.
In particular, the standard way is to:
Create a 'static' directory in the root of your application
Add the following to your application settings:
"static_path": os.path.join(os.path.dirname(file), "static")
Put the protovis-d3.2.js in your static directory