Hi there,
I was not able to find this with google, so putting here just to make it useful for django folks
So if I have a file on disk somewhere and I want to show this file in form
First I need to create dict with files
path = 'some/path/img.jpeg'
files = {}
files['pic'] = ImageFieldFile(instance=None, field=FileField(), name=path)
We need ImageFieldFile, because django forms is checking whether value has url attribute or not, it must have one.
I can’t just pass it as files keyword arg like this.
form = Form(data, files=files)
Because FileInput or ClearableFileInput doesn’t take any values from data or files, it takes only from initial.
So the right way appears to be
form = Form(data, initial=files)
How do you think guys, is it ok or may be another better way out there.