【发布时间】:2023-04-01 01:41:01
【问题描述】:
我是 web.py 的新手,我尝试创建一个下载命令。
我创建了这个:
import web
urls = (
'/', 'index',
'/download', 'Download'
)
class index:
def GET(self):
return "Hello, world!"
class Download:
def GET(self):
path = 'http:\\localhost:8080\C:\11\229077_6482396906_558_n.jpg'
web.header('Content-Disposition', 'attachment; filename="fname.ext"')
web.header('Content-type','images/jpeg')
web.header('Content-transfer-encoding','binary')
return open(path, 'rb').read()
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
我有两个主要问题:
当我输入
http://localhost:8080/download时,它给了我 500 内部服务器错误。为什么?我无法选择要下载的文件(只需手动更改路径参数)。我如何给这个函数外部参数?
【问题讨论】:
-
检查
path从您尝试读取文件的位置。它只是找不到那个文件。