你为什么不只使用ModelForm?
# forms.py# ...class MyForm(forms.ModelForm): class meta: model = MyModel# views.py# ... def my_view(request, id): instance = get_object_or_404(MyModel, id=id) form = MyForm(request.POST or None, instance=instance) if form.is_valid(): form.save() return redirect('next_view') return render(request, 'my_template.html', {'form': form})
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)