Multiple Static Directories in Python Tornado

狂风中的少年 提交于 2019-12-23 19:40:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!