当我更新updateview中的数据时,数据不会显示在字段中

时间:2018-02-06 09:02:20

标签: python django django-forms

更新视图中的数据时,数据未显示在字段中

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})

1 个答案:

答案 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})