内联表单集中的图像字段未填充
我有这段代码:
vehicle = get_object_or_404(Vehicle, stock_number=stock_number)
if request.method == 'POST':
vehicle_form = VehicleForm(request.POST, instance=vehicle)
photos = PhotosFormSet(request.POST, request.FILES, instance=vehicle)
if vehicle_form.is_valid() and photos.is_valid():
vehicle = vehicle_form.save()
photos.save()
request.user.message_set.create(message='The vehicle "%s" was edited
successfully.' % vehicle.__str__())
return HttpResponseRedirect("/vehicles/details/%s/" % stock_number)
else:
vehicle_form = VehicleForm(instance=vehicle)
photos = PhotosFormSet(instance=vehicle)
return render_to_response('vehicles/vehicles-add-edit.html',
{'vehicle_form':vehicle_form, 'photos': photos,},
context_instance=RequestContext(request))
除了 PhotosFormSet
中的 ImageField
之外,表单均已正确初始化。
I have this piece of code:
vehicle = get_object_or_404(Vehicle, stock_number=stock_number)
if request.method == 'POST':
vehicle_form = VehicleForm(request.POST, instance=vehicle)
photos = PhotosFormSet(request.POST, request.FILES, instance=vehicle)
if vehicle_form.is_valid() and photos.is_valid():
vehicle = vehicle_form.save()
photos.save()
request.user.message_set.create(message='The vehicle "%s" was edited
successfully.' % vehicle.__str__())
return HttpResponseRedirect("/vehicles/details/%s/" % stock_number)
else:
vehicle_form = VehicleForm(instance=vehicle)
photos = PhotosFormSet(instance=vehicle)
return render_to_response('vehicles/vehicles-add-edit.html',
{'vehicle_form':vehicle_form, 'photos': photos,},
context_instance=RequestContext(request))
The forms are initialized correctly except the ImageField
in PhotosFormSet
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你说它没有初始化时你是什么意思?你的意思是用原始数据填充吗?
HTML 文件输入字段永远不会填充现有数据 - 这是浏览器限制,与 Django 无关。这是一项安全措施,旨在阻止恶意网站欺骗您从计算机上传任意内容。
What do you mean when you say it's not initialized? Do you mean populated with the original data?
HTML file input fields are never populated with existing data - this is a browser restriction, nothing to do with Django. It's a security measure, to stop malicious sites tricking you into uploading arbitrary content from your computer.