I am trying to add image to my blog post but when i added this to my code
image = request.Post['image']
And i keep getting errors.
CodePudding user response:
Please try this.
def upload_file(request):
if request.method == 'POST':
form = UploadFileForm(request.POST, **request.FILES**)
if form.is_valid():
handle_uploaded_file(**request.FILES['image']**)
return HttpResponseRedirect('/success/url/')
else:
form = UploadFileForm()
return render(request, 'upload.html', {'form': form})
CodePudding user response:
It means that key 'image' does not exist. Try this:
if 'image' in request.FILES:
image = request.FILES['image']