在Django中获取ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION

Pra*_*mod 0 python django

我在Chrome浏览器中收到ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,并在Django中使用以下给定代码。

redirect_path = 'some-url'
response = HttpResponseRedirect(redirect_path)
response['Content-Disposition'] = 'attachment; filename=file-from-+324#10,+4324.mp3'
return response
Run Code Online (Sandbox Code Playgroud)

事情正在其他浏览器中找到。

请让我知道我在这方面做错了什么。

Ala*_*air 6

问题是文件名中有逗号。您应该在文件名中引用标题。我测试了以下视图在Chrome中的工作原理。

def my_view(request):
    response = HttpResponse('hello')
    response['Content-Disposition'] = 'attachment; filename="filename,with,commas.txt"'
    return response
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参见Chrome帮助论坛上的讨论