views:

19

answers:

1

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})

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?

+1  A: 

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/

Mark Lavin