我有一個表單,我想輸出爲自定義HTML。我forms.py:django自定義窗體選擇標記
from django import forms
from cdrs.models import Localitymayor
class SearchForm(forms.Form):
genus = forms.CharField(max_length=100)
species = forms.CharField(max_length=100)
island_group = forms.ModelChoiceField(queryset=Locality.objects.values_list('islandgroup', flat=True).distinct('islandgroup').exclude(islandgroup="n/a").order_by('islandgroup'))
island_name = forms.ModelChoiceField(queryset=Locality.objects.values_list('islandname', flat=True).distinct('islandname').exclude(islandname="n/a").order_by('islandname'))
在Django documentation它演示瞭如何輸出自定義HTML。但是顯然下面的模板代碼不會爲選擇下地幹活:
<form action="/search/" method="post">
{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.genus.errors }}
<label for="id_genus">Genus:</label>
{{ form.genus }}
</div>
...
<div class="fieldWrapper">
{{ form.island_group.errors }}
<label for="id_island_group">Island Group:</label>
{{ form.island_group }}
</div>
...
</form>
我如何控制選擇字段我ModelChoiceFields輸出?
oops - 固定錯字。 – 2011-12-19 22:00:55
這裏你有一個很好的起點:http://tothinkornottothink.com/post/10815277049/django-forms-i-custom-fields-and-widgets-in-detail – maazza 2013-11-20 11:27:49