caliph
caliph

Reputation: 1439

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?

Upvotes: 5

Views: 1620

Answers (1)

doniyor
doniyor

Reputation: 37846

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

Upvotes: 3

Related Questions