Model
class Details(models.Model):
image = models.ImageField(upload_to=‘images/’, blank=True, null=True)
form
class DetailsForm(forms.ModelForm):
class Meta:
model = Details
fields = [
‘image’
]
html
<div class="form-group">
<label for="id_images">Warehouse Image:</label>
<input type="file" id="image" name="image">
<div id="previewContainer" class="preview-container"></div>
</div>
view
def profile(request):
if request.method == ‘POST’:
form = DetailsForm(request.POST, request.FILES)
print(“Form data:”, form.data)
print(“Files data:”, form.files)
if form.is_valid():
details.save()
return redirect('management:search')
else:
form = DetailsForm()
return render(request, 'profile.html', {'form': form})
i tried by creating a new app it works
but in my existing app in html template i have used css and javascript , in that all the data get saved except image
Even i have tried to debug in that 1st it comes like
Files data: <MultiValueDict: {‘image’: [<InMemoryUploadedFile: download (1).jfif (image/jpeg)>]}>
later reading particular data image it says “image: None”
is it possible to save multiple image in single column ?
Thanks in advance…