'bytes' 对象没有属性“_committed”

'bytes' object has no attribute '_committed'

我将创建多图像添加页面。但是出现以下错误。你能帮帮我吗?我认为错误 views.py。我不确定。

注意:令人沮丧的是 Whosebug 要求提供详细解释。

错误:

AttributeError at /en/projects/multiimageadd/10/

'bytes' object has no attribute '_committed'
@login_required
@permission_required('is_superuser')
def MultiImageAdd(request, id):
    blog = BlogModel.objects.filter(id=id).first()
    if request.method == 'POST':
        images = request.FILES['images']
        for image in images:
            Images.objects.create(project=project, image=image)
        return redirect("home")
    return render(request,"multiImage.html")
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <div class="card">
                    <div class="card-header">
                    </div>

                    <div class="card-body">
                        <form class="needs-validation" method="POST" action="" enctype="multipart/form-data"
                              novalidate="">
                            {% csrf_token %}
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="form-group row">
                                        <label for="id_images" class="col-xl-3 col-md-4">Images:</label>
                                        <span class="form-control col-md-8">
                                            <input required type="file" name="images" id="id_images" multiple>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="pull-right">
                                <button class="btn btn-primary" type="submit">Save</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

models.py

class Images(models.Model):
    blog = models.ForeignKey(BlogModel, related_name='blogmodel', on_delete=models.CASCADE, blank=True,null=True)
    image = models.ImageField(blank=False, null=True)

您应该枚举文件处理程序,因此使用 .getlist(…) [Django-doc]:

获取处理程序
images = request.FILES<strong>.getlist(</strong>'images'<strong>)</strong>
for image in images:
    Images.objects.create(project=project, image=image)