class MyForm(forms.Form):
CHOICES = (('1', 'one',), ('2', 'two',))
one_or_two = forms.ChoiceField(widget=forms.RadioSelect, initial='1')
def show(request):
form = MyForm()
# render form
如何使字段 one_or_two 只读?
答案 0 :(得分:10)
您可以使用disabled属性。
one_or_two = forms.ChoiceField(widget=forms.RadioSelect(attrs={'disabled': 'disabled'}), initial='1')