指定Djang中的下载位置

2024-09-29 19:36:58 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法在Django中指定下载位置?在

我的页面允许用户

  • 单击在后台运行到EXE的按钮
  • 然后为用户提供一个新页面,其中提供了下载选项
  • 用户点击下载,下载它生成的最新文件

{a1}你不能在一个特定的位置强制下载一个HTML。我想知道Django是否有一个选项可以让您这样做。在

def DownloadZip(request, zipname, prodVersID):
    print(zipname)
    zip_path = "C:/fbw/firmware/main/sys/" + zipname
    zip_file =  open(zip_path, 'rb')
    response = HttpResponse(zip_file, content_type='application/zip')
    response['Content-Disposition'] = 'attachment; filename=%s' %zipname
    response['Content-Length'] = os.path.getsize(zip_path)
    zip_file.close()

    return response

Tags: pathdjango用户response选项页面contentzip
1条回答
网友
1楼 · 发布于 2024-09-29 19:36:58

经过进一步的研究,我得出结论,引用post也反映在Django上。Django不提供这样的功能,它是web浏览器的一个安全特性,不允许您指定下载位置。在

记入Darren

Whether the browser asks the user or not is down to the preferences in the browser.

You can't bypass those preference, otherwise it would violate user's security.

相关问题 更多 >

    热门问题