# Not displaying all the files I uploaded. Showing only one

**URL:** <https://forum.djangoproject.com/t/not-displaying-all-the-files-i-uploaded-showing-only-one/11022>\
**Category:** Using Django\
**Created:** [December 14, 2021, 3:43am UTC](https://forum.djangoproject.com/t/not-displaying-all-the-files-i-uploaded-showing-only-one/11022 "2021-12-14T03:43:56Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Stanley-Stones](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/stanley-stones/32/24079_2.png) [@Stanley-Stones](https://forum.djangoproject.com/u/Stanley-Stones)\
**Post date:** [September 22, 2024, 1:30pm UTC](https://forum.djangoproject.com/t/not-displaying-all-the-files-i-uploaded-showing-only-one/11022/12 "2024-09-22T13:30:45Z")

</div>

Just like this small project here. I uploaded multiple images but got only one image. I set validations in the views in other to know the cause and i got it out in the console with only one image and also with the form validation i set which states that form is Invalid

**models.py**

```auto
from django.db import models

class ImageUpload(models.Model):
  image = models.FileField(upload_to='images/')
  uploaded_at = models.DateTimeField(auto_now_add=True)

  def __str__ (self):
    return f"Image uploaded at {self.uploaded_at}"

```

**forms.py**

```auto
from django import forms
from .models import ImageUpload

class ImageUploadForm(forms.ModelForm):

  image = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': False})),

  class Meta:
    model = ImageUpload
    fields = ['image']
    

```

**views.py**

```auto
from django.shortcuts import render, redirect
from .forms import ImageUploadForm
from .models import ImageUpload

def upload_images(request):
  
  if request.method == 'POST':
    
    form = ImageUploadForm(request.POST, request.FILES)
    images = request.FILES.getlist('image')

    if form.is_valid():
      print('Valid Form')
    else:
      print('Form not Valid')
      
    for img in images:
      print(img)
      ImageUpload.objects.create(image=img)
      return redirect('upload_images')
   
  else:
    form = ImageUploadForm()
    
  images = ImageUpload.objects.all()
  return render(request, 'upload_images.html', {'form': form, 'images': images})

```

**upload\_images.html**

```auto
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Upload Images</title>
</head>
<body>
  <h1>Upload Images</h1>
    
  <form action="" method="post" enctype="multipart/form-data">
      
    {% csrf_token %}

    {{form.as_p}}

    <button type="submit">Submit</button>

  </form>

  <h2>Uploaded Images</h2>
  
  <div>
    {% for image in images %}
      <img src="{{ image.image.url }}" alt="Image" style="max-width: 200px;"/>
    {% endfor %}
  </div>
</body>
</html>

```

**My Console**

```auto
[22/Sep/2024 16:09:28] "GET /media/images/agent-1.jpg HTTP/1.1" 304 0
Form not Valid-------(My form validation output which i set)
mini-testimonial-2.jpg-------(Instead of all images i got only one)
[22/Sep/2024 16:09:43] "POST /images/ HTTP/1.1" 302 0

```

---

_[View the full topic](https://forum.djangoproject.com/t/not-displaying-all-the-files-i-uploaded-showing-only-one/11022)._
