def edit(request,id): edit_obj=Book.objects.get(pk=id) if GET请求: form=BookModelForm(instance=edit_obj) return render(reqeust,{"form":form}) ''' 渲染页面同添加页面 ''' else POST请求: form=BookModelForm(request.POST,instance=edit_obj) if form.is_valid(): # edit_obj.update(clean_data) form.save() return redirect("/") else: return render(reqeust,{"form":form})