'Django self.request.FILES.getlist

So I have changed the input's name attribute to some custom name, but the view calls form_invalid method. Why my Form isn't saving (validating)?

html:

<tr>
      <th><label for="id_photo">Image:</label></th>
      <td>
      <input type="file" name="custom_photo_name" accept="image/*" required id="id_photo" multiple>
      </td>
</tr>

the form:

class DateForm(forms.ModelForm):
    photo = forms.ImageField(required=False)
    
    class Meta:
        model = Date
        exclude = ('user',)

the view:

class UpdateDateView(LoginRequiredMixin, UpdateView):
    model = Date
    form_class = DateForm
    template_name = 'app/form/date_edit_form.html'

    @transaction.atomic
    def form_valid(self, form):
        date = form.save()
        self.request.FILES.getlist('custom_photo_name') # this returns an empty list []
        return super().form_valid(form)

Doesn't the self.request.FILES takes the values according to name attribute? Why can't I reach my files?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source