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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With