2011-01-08 13 views
1

발췌 :템플릿에 ChoiceField를 표시하는 방법은 무엇입니까? <br> forms.py에서

class ContForm(): 
    KafChoices = [(kaf.id, kaf.name) for kaf in Kaf.objects.all()] 
    kaf = forms.ChoiceField(choices = KafChoices, required = True) 

    class Meta: 
     model = Cont 

views.py :

def index(request): 
    return render_to_response('db3/index.html', 
     {'form': ContForm()}, 
     context_instance=RequestContext(request)) 

index.html을 :

{{ form.kaf }} 

것은 내가 출력 다음 얻을 :
django.forms. 0x01A110D0의 ChoiceField 개체
일반 필드 대신뭐가 문제 야?

답변

2

ContFormforms.Form에서 상속되지 않으므로?

편집 : 모델 양식처럼 보입니다.이 경우 ContForm(forms.ModelForm)이지만, form.kaf이 수행하는 모든 양식 클래스에서 상속하지 않으면이 자체로 수행 할 작업을 모르는이 python 개체를 가져옵니다.