内联表单集中的图像字段未填充 [英] Imagefield in Inline formset not populated

查看:42
本文介绍了内联表单集中的图像字段未填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码:

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 以外,其他表单均已正确初始化.

The forms are initialized correctly except the ImageField in PhotosFormSet.

推荐答案

当您说它没有初始化时,您是什么意思?您是说要填充原始数据吗?

What do you mean when you say it's not initialized? Do you mean populated with the original data?

HTML文件输入字段永远不会填充现有数据-这是浏览器的限制,与Django无关.这是一种安全措施,可以阻止恶意网站欺骗您,从您的计算机上载任意内容.

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.

这篇关于内联表单集中的图像字段未填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆