def add_config(request): if request.method == 'POST': form = ConfigForm(request.POST) if form.is_valid(): form.save(commit=True) return config(request) else: print form.errors else: form = ConfigForm() return render(request, 'cmdb/add_config.html', {'form': form})
def edit_config(request): if request.method == 'POST': r_id = request.POST["id"] pub_info = CM_CONFIG.objects.get(id=r_id) # 获取要更改行 form = ConfigForm(request.POST, instance=pub_info) if form.is_valid(): form.save() return config(request) else: print form.errors else: form = ConfigForm() return render(request, 'cmdb/add_pub.html', {'form': form})