Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Redirect after HttpResponse

I am generating a report download in a view and starting the download after processing the POST data. That means the user sends a form and the download starts:

views.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

What I need is a page refresh after the download (or a redirect). How can I achieve this?

like image 202
caliph Avatar asked Oct 19 '22 17:10

caliph


1 Answers

I would just do it in simple logic with javascript:

user clicks the link

/download_file_now/

and comes to /file_downloaded/ where the download starts and after 3 seconds, you just redirect the page via js

location.replace('/another_url/');

to detect if the download is ready is not easy

like image 154
doniyor Avatar answered Oct 21 '22 13:10

doniyor