【flask】TypeError: send_file() got an unexpected keyword argument 'attachment_filename'の解決方法

send_file() send_from_directory()等でattachment_filenameを設定するとエラーが出る件

先日、send_file関数を使用したときに、上記のエラーが出て原因が分かったので備忘録としてメモしておきます。

flask公式では、send_file関数の引数にattachment_filenameが書かれている。

attachment_filename – the filename for the attachment if it differs from the file’s filename.

flask.send_file — Flask API (tedboy.github.io)

なので、これを用いようと思うとエラーが出る。。。

解決方法

よくよく調べてみると、どうやらattachment_filenameは使えなく、download_nameで使えるようになるらしい。

なので、download_nameに変えたところ、できました。

ご参考になれば幸いです。なお、プログラミング初学者なため至らない点があればご指摘ください。

参考文献

python - Getting an error attachment_filename does not exist in my docker environment - Stack Overflow

(Visited 204 times, 1 visits today)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA