Django下载文件集正确的名称
现在我使用以下功能下载文件:Django下载文件集正确的名称,django,Django,现在我使用以下功能下载文件: def download_xlsx(request): user = request.user file_name = request.GET['file_name'] file_path='main_app/static/xlsx/' + str(user.id) + '/' + file_name if os.path.exists(file_path): with open(file_path, 'rb') as
def download_xlsx(request):
user = request.user
file_name = request.GET['file_name']
file_path='main_app/static/xlsx/' + str(user.id) + '/' + file_name
if os.path.exists(file_path):
with open(file_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
response['Content-Disposition'] = "inline; filename=%s" % file_name
return response
使用以下url
我下载了名为“download_xlsx”的文件
我试着写这样的东西:
response['Content-Disposition'] = "inline; filename='+ file_name
但是没有帮助。
如何将文件重命名为file\u name
var?
UPD:这似乎是非英语文件名的问题。但是仍然不知道如何处理它这样工作(问题在于编码)
如果硬编码
文件名
变量,输出是什么?如果硬编码,输出是正确的
response['Content-Disposition'] = "inline; filename=%s" % file_name.encode('utf-8')