问题
I have a directory structure setup like:
root/
js/
css/
libs/
index.html
From Tornado, I want to serve js, css, and libs as static directories, but I can only find out how to serve one of them. Can this be done?
回答1:
No its not possible.
You could ofcourse create a new folder -- parent, and place js, css and libs inside of that folder, and then speciy that parent folder as the 'static_path'
nb. "In production, you probably want to serve static files from a more optimized static file server like nginx"
回答2:
As Schildmeijer quoted from the Tornado website, I recommend using Nginx to serve static files. Having this setup early on is very convenient and easy. This also allows you some other potential benefits in the future:
- Using Nginx for load balancing
- Using Nginx to handle SSL
回答3:
See https://stackoverflow.com/a/10165739/1813988
You can set the static path for different assets by setting handlers like this (and remove the static_path
setting in Application):
handlers = [ (r'/favicon.ico', tornado.web.StaticFileHandler, {'path': favicon_path}), (r'/static/(.*)', tornado.web.StaticFileHandler, {'path': static_path}), (r'/', WebHandler) ]
来源:https://stackoverflow.com/questions/3929393/multiple-static-directories-in-python-tornado