我有一个表单,我想输出为自定义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