djangoを使用して、Webサイトからのチュートリアルに従って画像をアップロードしようとしています。私views.py
が持っている:
def picture_upload(request):
"""
form to upload an image together with a caption.
saves it as a Picture in the database on POST.
shows the last uploaded picture and let's you upload another.
"""
picture = None
if request.method != 'POST':
form = PictureUploadForm()
else:
form = PictureUploadForm(request.POST, request.FILES)
if form.is_valid():
# an UploadedFile object
uploadedImage = form.cleaned_data['image']
caption = form.cleaned_data['caption']
# limit to one database record and image file.
picture, created = Picture.objects.get_or_create(picture_id=1)
if not created and picture.get_image_filename():
try:
os.remove( picture.get_image_filename() )
except OSError:
pass
# save the image to the filesystem and set picture.image
picture.save_image_file(
uploadedImage.filename,
uploadedImage.content
)
# set the other fields and save it to the database
picture.caption = caption
picture.save()
# finally, create a new, empty form so the
# user can upload another picture.
form = PictureUploadForm()
return render_to_response(
'example/picture_upload.html',
Context(dict( form=form, last_picture=picture) ) )
エラーは次のように述べています。
グローバル名「コンテキスト」が定義されていません」コードの最後の行「views.pyinpicture_upload、行111」。
どうすればこの問題を解決できますか?