本文介绍了为Django表单设置下拉菜单的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 加载表格时,我无法为下拉菜单设置默认值。I am unable to set default value for a dropdown while loading forms.这是代码state = forms.TypedChoiceField(choices = formfields.State)State = ( ('QC_APPROVED','QC_APPROVED'), ('REVERT','REVERT'), ('FIXED','FIXED'), )如果我想将默认状态设置为FIXED。我正在编写这段代码If I want to make the default state as FIXED. I am writing this codestate = forms.TypedChoiceField(choices = formfields.State, default = 'FIXED')如果执行上述代码,则会出现以下错误。If I execute the above code I am getting the below error.Exception Value: __init__() got an unexpected keyword argument 'default'有人可以帮忙吗?推荐答案state = forms.TypedChoiceField(choices=formfields.State, initial='FIXED')如文档所示: http://docs.djangoproject.com/en/dev/ref/forms / fields /#initial 这篇关于为Django表单设置下拉菜单的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 03:17