Python 使用web.py创建下载命令
我在web.py中创建了一个新文件,并尝试创建一个下载命令 我创建了一个:Python 使用web.py创建下载命令,python,web.py,Python,Web.py,我在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:
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个内部服务器错误。为什么?2.例如,将以下内容添加到代码中:
filename = web.input().file
因此,在输入链接时,它将返回所需的文件名:
yoursite.tld/downloads?file=FILENAME
请在此处阅读有关此主题的更多信息:检查您试图从中读取文件的路径。它就是找不到那个文件。