内联表单集中的图像字段未填充

发布于 2024-08-20 13:05:57 字数 927 浏览 26 评论 0原文

我有这段代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏月而来 2024-08-27 13:05:57

当你说它没有初始化时你是什么意思?你的意思是用原始数据填充吗?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文