Is there an easy way to do the following?
after getting the request in the view,
send back to the user a file, plus a re-rendered template of the page?
something like "merging" reponse with a file and render_to_response
This is how I return a response with a file:
filename = "/path/to/somewhere"
wrapper = FileWrapper(open(filename))
content_type = mimetypes.guess_type(filename)[0]
response = HttpResponse(wrapper,content_type=content_type)
response['Content-Length'] = os.path.getsize(filename)
response['Content-Disposition'] = "attachment; filename=%s"%filename
return response
This is how I return an ordinary template with rendered data:
data = getData()
return render_to_response('../templates/some_template.html', {'data': data,})
(I might have dropped some important lines with copy-paste, but to make my point - this code works, the problem is not with these two code samples)
the question is: how do I "merge" both of them together?
is there a simple way to do this with django standard functionality?
Do I have to use Ajax for this? (I'm not familiar with ajax... so if there's a way to do this without, it's preferable)
Thanks,
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…