admin管理员组文章数量:1277898
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.
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.
Share Improve this question asked Mar 2, 2011 at 11:55 SwarajSwaraj 1,2432 gold badges13 silver badges22 bronze badges1 Answer
Reset to default 12You 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
- Refer to the file /static/protovis-d2.2.js in your HTML
本文标签: pythonTrouble with Tornado and JavaScript LibrariesStack Overflow
版权声明:本文标题:python - Trouble with Tornado and JavaScript Libraries - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741213635a2359620.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论