Django,如何更新图像

2024-05-28 19:50:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望标题足以理解我的问题,如下图所示,我可以从我的数据库中获取pciture,问题是当我更新数据时,我没有更改显示的图片,这会导致错误,错误的原因是我没有从html获取任何数据

<label for="myfile3">
    <img id="output3"  src="{{selectbanner.image.url}}" style="height:225px;width:250px;" class="subimage"/><br>
    <input type="file" accept="myfile" id="myfile3" name="image" value="{{selectbanner.image.url}}" onchange="loadFile3(event)"  >
</label>
<script>
     var loadFile3 = function(event) {
     var reader = new FileReader();
     reader.onload = function(){
     var output3 = document.getElementById('output3');
     output3.src = reader.result;
     };
     reader.readAsDataURL(event.target.files[0]);
     };
</script>

这是我的观点

image = request.FILES.get('image')
print(image)

update = Banner.objects.get(id=banner_id)
    update.image = image
    update.title = Title
    update.sub_title = Sub
    update.description = Description

    update.save()

    return redirect('Banners')

enter image description here


Tags: 数据imagesrceventidurlvar错误

热门问题