[Fixed]-ImageField() not saving images in ModelForm – Django/Python

41👍

You should add the enctype=multipart/form-data attribute to the <form> tag:

<form method='POST' action='{{ action_url }}' enctype='multipart/form-data'>

2👍

except for adding enctype=multipart/form-data, another possible reason that your image is not saving in modelform can be adding request.FILES in your POST condition:

if request.method == 'POST':
    form = forms.ProjectCreateForm(request.POST, instance=project)

should be:

if request.method == 'POST':
    form = forms.ProjectCreateForm(request.POST, request.FILES, instance=project)

0👍

data.profile_pic = request.FILES[‘profile_pic’]

use request.FILES

Leave a comment