2

Python内でファイルの HTTP ヘッダーを変更する必要があります。私がここに従っている例: http://tmanstwobits.com/convert-your-web-pages-to-pdf-files-using-phantomjs.html

Djangoなしで複製しようとしている基本的なコードは次のとおりです。

file_name = '/tmp/current_page.pdf'
url = ('user_current_url')
external_process = Popen(["phantomjs", phantomjs_script, url, file_name],
                         stdout=PIPE, stderr=STDOUT)
# Open the file created by PhantomJS
return_file = File(open(file_name, 'r'))
response = HttpResponse(return_file, mimetype='application/force-download')
response['Content-Disposition'] = 'attachment; filename=current_page.pdf'
# Return the file to the browser and force it as download item
return response

HTTP ヘッダーを変更できる urllib.urlopen を使用してみましたが、他の問題が発生し、最善の方法とは思えません。どうすればこれを達成できますか?

4

1 に答える 1