1

我想在下载文件后重定向到另一个视图,但是当我完成下载后什么也没有发生,它仍然在同一页面中。下载工作完美。任何想法??

视图.py:

#The function that downloads the file
def download_file(path, format, fileName):

    path = path+"."+format          
    filename = os.path.basename(path)    
    mimetype, encoding = mimetypes.guess_type(filename)

    if fileName==None: fileName = filename
    else: fileName = fileName+"."+format

    response = HttpResponse(mimetype=mimetype)
    response['Content-Disposition'] = 'attachment; filename=%s' %fileName
    response.write(file(path, "rb").read())

    return response


def download_downloaded_track(request, downloadedTrack_id):

     dt = get_object_or_404(DownloadedTrack, id=downloadedTrack_id)

     if request.method=='POST':
         form = DownloadDownloadedTrackForm(request.POST)

         if form.is_valid():
             ...
             return download_file(downloadedTrackRoute+dt.fileName,format, name)

             return HttpResponseRedirect(reverse('profile_detail'))            

    form = DownloadDownloadedTrackForm(initial={'format':'gpx'})
    return render(request,'principal/downloadedTrack.html',{'form':form,'zone':dt.zone,'downloadedTrack':dt, 'layer':'downloadDownloadedTrack'})
4

0 回答 0