2014-06-19 3 views
0

내 템플릿에 드롭 다운 메뉴를 표시하기 위해 노력하고있어 정의,하지만 난장고 1.6 이름은

여기
File "forms.py" in DropdownSelectionForm 
    101.  selection = forms.ChoiceField(choices=MY_CHOICES, widget = Select) 

Exception Type: NameError at/
Exception Value: name 'Select' is not defined 

내가 양식을 보여주기 위해 노력하고있어 템플릿입니다 다음과 같은 오류를 얻을하지 않습니다

여기
<form action="/doclistings/" method="post" >{% csrf_token %} 
      <select class="form-control" id="s1" NAME="selection"> 
       <option><b>Find a Doctor...</b></option> 
       {% for value, text in form.selection.field.choices %} 
       <option value="{{ value }}">{{ text }}</option> 
       {% endfor %} 
      </select> 

는 forms.py입니다

MY_CHOICES = (
    ('Dermatologist', 'Dermatologist'), 
    ('Dentist', 'Dentist'), 
    ('Opthalmologist', 'Opthalmologist'), 
) 

class DropdownSelectionForm(forms.Form): 
    selection = forms.ChoiceField(choices=MY_CHOICES, widget = Select) 
Select을 찾을 수 없습니다, 당신이을 가져온 참조

답변

2

Python의 다른 요소와 마찬가지로 개체를 올바르게 참조해야합니다. 이 경우 Select는 ChoiceField와 똑같이 forms 모듈을 통해 사용할 수 있습니다.

selection = forms.ChoiceField(choices=MY_CHOICES, widget=forms.Select) 
1

파이썬, 시도해보십시오. widget=forms.Select