文件下载

  • 下载注意要素

    • 打开文件 需要使用 rb文件操作模式
    • 指定返回值类型 application/octet-stream
  • 代码

    from django.http import FileResponse
    def get(request):
      file = open('static/upload/11.1.1.md', 'rb')
      response = FileResponse(file)
      response['Content-Type'] = 'application/octet-stream'
      response['Content-Disposition'] = 'attachment;filename="xlsx_file.xlsx"'
      return response
    

results matching ""

    No results matching ""