更新视图中的数据时,数据未显示在字段中
def dis_update(request, pk, template_name='sales/distributor_form.html'):
alldistributor = get_object_or_404(Distributor, pk=pk)
if request.method=='POST':
form = DistributorForm(request.POST, instance=alldistributor)
if form.is_valid():
form.save()
return redirect('index.html')
else:
form=DistributorForm()
return render(request, template_name, {'form':form})
答案 0 :(得分:-1)
def dis_update(request, pk, template_name='sales/distributor_form.html'):
alldistributor = get_object_or_404(Distributor, pk=pk)
if request.method=='POST':
form = DistributorForm(request.POST, instance=alldistributor)
if form.is_valid():
form.save()
return redirect('index.html')
else:
form=DistributorForm(instance=alldistributor)
return render(request, template_name, {'form':form})
else:
form = DistributorForm(instance=alldistributor)
return render(request, template_name, {'form': form})