@route('/download/<hash>')
def download_file(hash):
pass
比如写成这种restful形式, 当用户访问带hash的连接的时候下载对应文件, 服务器的response该怎么写?
@route('/download/<hash>')
def download_file(hash):
pass
比如写成这种restful形式, 当用户访问带hash的连接的时候下载对应文件, 服务器的response该怎么写?
@route('/download/<filename:path>')
def download(filename):
return static_file(filename, root='/path/to/static/files', download=filename)
文档中不是有示例了么?打开 http://bottlepy.org/docs/dev/tutorial.html#generating-content 搜 Force Download.
2 回答5.1k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
4 回答1.4k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
3 回答1.2k 阅读✓ 已解决
1 回答1.7k 阅读✓ 已解决
1 回答1.2k 阅读✓ 已解决
除了static_file之外,还可以直接return 字符串就行,如果要具体设置content-type之类的,可以修改bottle.response的相关属性