https://www.cnblogs.com/wupeiqi/articles/6144178.html
class F2Form(forms.Form):
title1=fields.CharField()
detail=fields.CharField(
widget=widgets.Textarea
)
processer=fields.CharField( widget=widgets.Select(choices=models.UserInfo.objects.values_list('nid','username'))
) def edit_trouble(request):
if request.method=='GET':
id=request.GET.get('p')
print(id)
c=models.Trouble.objects.filter(id=id).all().first()
print(c.title)
print(c.processer.username)
data={}
data['title1']=c.title
data['detail']=c.detail
data['processer']=c.processer_id obj=F2Form(data=data) return render(request,'edit.html',locals())
else:
obj=F2Form(request.POST)
if obj.is_valid():
print(obj.cleaned_data) return HttpResponse('ok')
通过form组件实现保留上次的值