2012-09-26 31 views
5
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 

Làm cách nào để tạo trường one_or_two chỉ đọc?Cách tạo ChoiceField chỉ đọc ở dạng django

+0

Bạn đã thử xem nội dung này chưa? http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-b – Amit

+0

Có, nó không 't làm việc cho tôi. Tôi đang mở rộng forms.Form không giống như ModelForm như trong câu hỏi nhọn. – Nullpoet

Trả lời

8

Bạn có thể sử dụng thuộc tính bị tắt.

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

Nó hoạt động .. Cảm ơn! – Nullpoet

Các vấn đề liên quan