以Django输出PDF作为附件并重新加载 [英] Outputting PDF with Django as attachment and reload
问题描述
response = HttpResponse(我的django)生成一个pdf并返回响应作为视图中的附件。 (mimetype ='application / pdf')
response ['Content-Disposition'] ='attachment;文件名= somefilename.pdf'
类似于文档(http://docs.djangoproject.com/en/dev/howto/outputting- pdf /#write-your-view )
什么是重新加载页面的最佳方式?
这没有解决(表单触发pdf生成):
$('#the_form')。 submit(function(){
location.reload();
});
非常感谢
丹尼
不要重新加载。而是创建一个视图,它是窗体的目标。该视图在从真实Web服务器传递的目录中生成PDF,然后将用户发送到专用URL,在那里他可以下载文件(使用HttpResponseRedirect)。
I´m using django to generate a pdf and return the response as an attachment in the view.
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
Similar to the way described in the doc (http://docs.djangoproject.com/en/dev/howto/outputting-pdf/#write-your-view)
What is the best way to reload the page?
This didn´t work out (the form triggers the pdf generation):
$('#the_form').submit(function(){
location.reload();
});
Thanks a lot, Danny
Don't reload. Instead create a view which is the target of the form. The view generates the PDF in a directory that is delivered from the real web server and then sends the user to the appropriated URL, where he can download the file (use HttpResponseRedirect).
这篇关于以Django输出PDF作为附件并重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!