如何在django表单中只读取ChoiceField

时间:2012-09-26 18:42:45

标签: django django-forms django-templates

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 只读?

1 个答案:

答案 0 :(得分:10)

您可以使用disabled属性。

one_or_two = forms.ChoiceField(widget=forms.RadioSelect(attrs={'disabled': 'disabled'}), initial='1')