How to properly pass image file to Form

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.

I’m not sure I understand what you’re trying to accomplish with this.

For a file upload field in a form, you cannot supply an initial value that will cause that file to be uploaded from the form.

And any path references you’re using in your code are going to be relative to the server, not the browser viewing this page.

So what is your objective here?

Hello, KenWhitesell, my objective is to make form know, that Form has uploaded form, so it can show clear (remove) the image button, and in my case, it shows preview of image - gets url from url attribute of ImageField, using custom widget with preview and remove button.