请问我错过了什么。当我想提供已下载到磁盘上的视频文件时,我不断在浏览器中收到内部服务器错误。这是我的代码:视图函数
@view_config(name='download_video')
def dl(request):
url = request.params.get('url')
camefrom = request.params.get('came_from')
path_dir = request.registry.settings['app.download_path']
result= save_to_disk(url, path_dir)
if result:
filename = result['filename']
filepath = os.path.abspath(os.path.join(path_dir,filename))
file_exists = os.path.exists(filepath)
if file_exists:
res = FileResponse(filepath,content_type='video/mp4')
res.headers['Content-Length'] = os.path.getsize(filepath)
res.headers['Content-Disposition'] = 'attachment;filename=%s'%filename
return res
request.session.flash(_("Error downloading video, please check your network","danger"))
return HTTPFound(location=camefrom)
模板
<a tal:attributes="href api.url(api.root, '@@download_video', query={'came_from': request.url,'url':context.video_url})" class="btn">Download</a>
视频下载,我可以在文件夹中看到它,但我不断收到内部服务器错误,而在浏览器上没有回溯
我的应用依赖于 Kotti cms