# Django ModelForm - Image Upload Fail

**URL:** <https://forum.djangoproject.com/t/django-modelform-image-upload-fail/30449>\
**Category:** Mystery Errors\
**Created:** [April 23, 2024, 8:58am UTC](https://forum.djangoproject.com/t/django-modelform-image-upload-fail/30449 "2024-04-23T08:58:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yunusolcar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/yunusolcar/32/20758_2.png) [@yunusolcar](https://forum.djangoproject.com/u/yunusolcar)\
**Post date:** [April 23, 2024, 8:58am UTC](https://forum.djangoproject.com/t/django-modelform-image-upload-fail/30449/1 "2024-04-23T08:58:26Z")

</div>

Greetings. I’m doing an event creation project with Django. I’m having trouble **uploading images**. It uploads empty images. I can’t find where I made a mistake. I would be very grateful if you could help me. Thanks for your help. (I made media root settings)

**forms.py**

```auto
class CreateEventForm(forms.ModelForm):
    class Meta:
        model = Event
        fields = ['name', 'description', 'image', 'event_date', 'location']

        widgets = {
            'name': widgets.TextInput(attrs={'class': 'form-control'}),
            'description': widgets.TextInput(attrs={'class': 'form-control'}),
            'location': widgets.TextInput(attrs={'class': 'form-control'}),
            'image': widgets.FileInput(),
            'event_date': widgets.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
            # 'participants': widgets.SelectMultiple(attrs={'class': 'form-control'}),
            'creator': widgets.HiddenInput(),
        }

```

**html**

```auto
<form action="create-event" method="POST" enctype="multipart/form-data">
                                {% csrf_token %}
                                {{ form.as_p }}
                                <div class="form-group">
                                    <button type="submit" class="btn btn-primary btn-lg btn-block mt-3">Submit</button>
                                </div>
                            </form>

```

**views.py**

```auto
class CreateEvent(View):
    def get(self, request):
        form = CreateEventForm()
        return render(request, 'event/create-event.html', {'form': form})

    def post(self, request):
        form = CreateEventForm(request.POST)
        if form.is_valid():
            event = form.save(commit=False)
            event.creator = request.user
            event.save()
            return redirect('create-event')
        else:
            return render(request, 'event/create-event.html', {'form': form})

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 23, 2024, 11:51am UTC](https://forum.djangoproject.com/t/django-modelform-image-upload-fail/30449/2 "2024-04-23T11:51:18Z")

</div>

You need to include the `request.FILES` parameter in your `CreateEventForm` call. See [File Uploads | Django documentation | Django](https://docs.djangoproject.com/en/5.0/topics/http/file-uploads/)

---

<div class="post-metadata">

**Author:** ![yunusolcar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/yunusolcar/32/20758_2.png) [@yunusolcar](https://forum.djangoproject.com/u/yunusolcar)\
**Post date:** [April 23, 2024, 12:10pm UTC](https://forum.djangoproject.com/t/django-modelform-image-upload-fail/30449/3 "2024-04-23T12:10:34Z")

</div>

ah, thank you \<3 You are great.
