目前我有一些类似的东西:
Currently I have something like:
def my_view(request) if request.method == 'POST': form = MyForm(request.POST, request.FILES) if form.is_valid(): form.save() redirect() else: form = MyForm() return render_to_response('form.html', {'form': form})在表单验证错误中,与request.POST相关联的所有字段都被重新填充,但request.FILES的字段为空。这是一个已知的Django限制,还是有什么可以对我的文件域进行重新填充?
On a form validation error, all the fields associated with request.POST are repopulated but the fields with request.FILES are empty. Is this a known Django limitation or is there something I can do to my the file fields repopulate?
推荐答案不,和浏览器问题一样多的Django问题。文件字段不能用初始值填充,否则在不知情的情况下,有恶意的形式从用户的机器上传文件将是微不足道的。有关于django-users邮件列表中有关于此的几个线程: groups.google/group/django-users/browse_thread/thread/14922dca454e3782/ groups.google/group/django-users/browse_thread/thread/f9fb21ddb4039b33/
No and this isn't as much a Django issue as a browser issue. File fields cannot be populated with an initial value otherwise it would be trivial to have a malicious form to upload files from the user's machine without their knowledge. There have been a couple threads about this on the django-users mailing list: groups.google/group/django-users/browse_thread/thread/14922dca454e3782/ groups.google/group/django-users/browse_thread/thread/f9fb21ddb4039b33/
更多推荐
Django是否在表单错误时重新填充文件字段?
发布评论