Trying to preview an image in django store site before saving the form

I am trying add a product to my django store, The issue for me is that i can not see preview of a image which is uploaded before saving the product.
As per the billow image of my site i can not see the preview of the image that i added and cannot add multiple images at the same place can you please help me with this please.


Thank you!

Keep in mind that before you click Save (or Submit or whatever that button is named), you have not yet actually uploaded the file. All you have done at this point is tell the browser which file to upload when the form is being submitted.

You’ve got a couple of options here to achieve what I think you’re trying to do:

  1. Using JavaScript, load the image directly in the browser from the local file and display it.
  2. Create an Admin action to let you submit the form, and then take you to a “Preview Page” to look at what has been uploaded before saving it to the database.

Hi Sir,
Thank you for the suggestion can you please explain me the 2nd step sir.

The referenced documentation page does a better job than what I can do here.

1 Like

Ok sir
thank you for the reply

Bringing the discussion back here from the replicated post - I don’t know why you think you can do what you want to do without either some custom JavaScript or custom forms.

Yes, you can add a related model to allow you to add an inline formset to your admin form, allowing you to upload multiple files with a foreign key relationship to your base model. But it’s still not going to provide you with a preview facility of those images.

Django can’t display images for preview if it doesn’t have them, and the files don’t get sent to the server until the form is submitted.

Therefore, you only have the two choices outlined above. You can either write some JavaScript to give you an image preview in the browser, or you can create something like a Django Admin action to give you a preview page after the images have been uploaded.

Ok Sir,
I will try these. And will let you know if any issues.
Thank you