Django是否在表单错误时重新填充文件字段?

编程入门 行业动态 更新时间:2024-10-25 15:21:32
本文介绍了Django是否在表单错误时重新填充文件字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

目前我有一些类似的东西:

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是否在表单错误时重新填充文件字段?

本文发布于:2023-11-27 19:39:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639342.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   表单   错误   文件   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!