ユーザーがリンクをクリックしたときにブラウザーで開くのではなく、プロジェクト ディレクトリ内の PDF ファイルをダウンロードできるようにしたいと考えています。
この質問に従いました Djangoでダウンロードするファイルを生成しています
しかし、私はエラーが発生しています:
Exception Type: SyntaxError
Exception Value: can't assign to literal (views.py, line 119)
Exception Location: /usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in import_module, line 35
ダウンロードリンクを作成しました:
<a href="/files/pdf/resume.pdf" target="_blank" class="btn btn-success btn-download" id="download" >Download PDF</a>
urls.py:
url(r'^files/pdf/(?P<filename>\{w{40})/$', 'github.views.pdf_download'),
ビュー.py:
def pdf_download(request, filename):
path = os.expanduser('~/files/pdf/')
f = open(path+filename, "r")
response = HttpResponse(FileWrapper(f), content_type='application/pdf')
response = ['Content-Disposition'] = 'attachment; filename=resume.pdf'
f.close()
return response
エラー行は次のとおりです。
response = ['Content-Disposition'] = 'attachment; filename=resume.pdf'
ダウンロードできるようにするにはどうすればよいですか?
ありがとう!
アップデート
Firefox では動作しますが、Chrome v21.0 では動作しません。