gpt4 book ai didi

Django:在 HttpResponse 之后重定向

转载 作者:行者123 更新时间:2023-12-01 04:58:40 26 4
gpt4 key购买 nike

我正在 View 中生成报告下载并在处理 POST 数据后开始下载。这意味着用户发送表单并开始下载:

View .py

def export(request):
if request.method == 'POST' and 'export_treat' in request.POST:
form1 = TransExport(request.POST, instance= obj)
if form1.is_valid():
...
...
response=HttpResponse(ds.xls,content_type="application/xls")
response['Content-Disposition'] = 'attachment; filename="Report_Behandlungen.xls"'
return response

我需要的是下载(或重定向)后的页面刷新。
我怎样才能做到这一点?

最佳答案

我只会用 javascript 以简单的逻辑来做:

用户点击链接

/download_file_now/

并来到 /file_downloaded/下载开始的地方,3 秒后,您只需通过 js 重定向页面
location.replace('/another_url/');

检测下载是否准备好并不容易

关于Django:在 HttpResponse 之后重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34830754/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com