下载文件后的Django Redirect

时间:2013-08-03 19:11:37

标签: django django-views

我想在下载文件后重定向到另一个视图,但是当我完成下载时没有任何反应,它仍然保留在同一页面中。 dwonloading工作得很好。有什么想法??

Views.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'})

0 个答案:

没有答案