我正在尝试创建一个表单,您必须在其中选择一年。我很确定这真的很容易,但我不知道为什么会出现一些错误。
主要错误是这样的:
'AbiturForm' object has no attribute 'fields'
我的班级形式为:
class AbiturForm(forms.Form):
year=forms.CharField(widget=forms.Select(),required=False)
abitur=forms.BooleanField(required=False)
def __init__(self):
choices=[(x,x) for x in range(1900,2000)]
self.fields['year'].choices=choices
我的模板:
{% extends "home/portal.html" %}
{% block body %}
<div id="content-main">
<div class="module">
<h2>Suche:</h2>
<form action="/suchen/abitur/" method="post">
{% csrf_token %}
<table>
<tr>
<td><label><b>Jahr:</b></label></td>
<td>
<select style="width:200px" name="year" id="year">
</select>
</td>
</tr>
<tr>
<td><label><b>Abitur?:</b></label></td>
<td>
<input type="checkbox" name="abitur" id="abitur" class="texto" />
</td>
</tr>
</table>
<input type="submit" value="Speichern" class="button"/>
</form>
</div>
</div>
{% endblock %}
任何帮助,将不胜感激。
谢谢 :)