繁体   English   中英

托管用于下载Python Tornado的静态文件

[英]Hosting static file for Download Python Tornado

嘿,我正在努力使用服务器上的Python和Tornado下载静态文件。

class templateHandler(tornado.web.RequestHandler):
def get(self):
    self.write("""
    <a href="/download"> Download </a>
    """)

application = tornado.web.Application([
(r"/", MyFormHandler),
(r"/results", MyFormHandler),
(r"/multi", MyFileHandler),
(r"/upload",MyFileHandler),
(r'/download',tornado.web.StaticFileHandler,{'path':"L:/Template.csv"}),
(r'/template', templateHandler),
(r"/SFA",SFAHandler),
])

有人可以帮我吗。 我对文件处理程序的工作方式不是100%肯定。 谢谢你的帮助!

编辑:这是错误消息:

ERROR:root:Uncaught exception GET /download (10.18.4.160)
HTTPRequest(protocol='http', host='IPadress', method='GET', uri='/download', version='HTTP/1.1', remote_ip='IPaddress', body='', headers={'Connection': 'keep-alive', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', >'Referer': 'IPadress/template', 'Host': 'IPaddress', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0'})
Traceback (most recent call last):
  File "WEB.PY LOCATION", line >988, in _execute
    getattr(self, self.request.method.lower())(*args, **kwargs)
TypeError: get() takes at least 2 arguments (1 given)
ERROR:root:500 GET /download (IPaddress) 0.00ms

我在想它与StaticFileHandler.get有关,期望路径,通常它不提供单个文件,而是提供文件目录,并使用文件名,我现在没有时间去研究它,但是应该是这样的

(r'/download/(.*)',tornado.web.StaticFileHandler,{'path':"L:/"}),

现在,如果你去

/download/Template.csv它应该为您服务。 抱歉,我现在没有时间调查消息来源以进行确认

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM