Django是否在表单错误时重新填充文件字段? [英] Does Django repopulate file fields on form error?

查看:79
本文介绍了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邮件列表中有关于此的几个线程:

http://groups.google.com/group/django-users/browse_thread/thread/14922dca454e3782/

http://groups.google.com/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:
http://groups.google.com/group/django-users/browse_thread/thread/14922dca454e3782/
http://groups.google.com/group/django-users/browse_thread/thread/f9fb21ddb4039b33/

这篇关于Django是否在表单错误时重新填充文件字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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