您好,我正在尝试在 ChoiceField
上选择一个选项时提交表单
class ActionForm(forms.Form):
""" Holds the options for mailbox management """
choices = ['create new folder', 'delete', 'read', 'unread']
action = forms.ChoiceField(choices=choices, attrs={'onchange': 'actionform.submit();'})
但现在我在尝试加载表单时遇到无效语法。我很确定 attrs={'onchange': 'actionform.submit();'})
是问题所在,但不确定该怎么做。
最佳答案
action = forms.ChoiceField(choices=choices,
widget=forms.Select(attrs={'onchange': 'actionform.submit();'}))
另外,choices
列表应该包含包含两个内容的项目:
choices = [(0, 'create new folder'), (1, 'delete'), (2, 'read'), (3, 'unread')]
关于python - django 在更改时提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23943671/