ファイルのアップロード
開発のプロが教える標準Django完全解説―Webアプリケーションフレームワーク (デベロッパー・ツール・シリーズ) | |
増田 泰 中居 良介 露木 誠 松原 豊 おすすめ平均 なんとか読み抜きました 実用的な良書 最初から最後までDjango 初心者から中上級者までお薦めできる良書 Amazonで詳しく見る by G-Tools |
import os.path from django.http import HttpResponse from django.shortcuts import render_to_response def upload(request): if request.method == 'POST': filename = request.FILES["upfile"]["filename"] content = request.FILES["upfile"]["content"] path = os.path.join('/home/hoge/temp/', filename) file = open(path, mode='w') file.write(content) file.close() return HttpResponse("File Upload Test. filename %s" % filename) return render_to_response('upload.html')
ビュー関数を上のようにすると、
とエラー表示される。ビュー関数の中の
filename = request.FILES["upfile"]["filename"]
でひっかかる。バージョンが新しくなったからか?
Django v1.0 documentation ファイルアップロードあたりのオンラインドキュメントを読んで検討する。