我正在尝试使这个简单的代码起作用:
表格.py
class TestForm(forms.Form):
start_date = forms.DateField(widget=SelectDateWidget())
end_date = forms.DateField(widget=SelectDateWidget())
视图.py
def test(request):
form = TestForm(request.GET)
if form.is_valid():
start = request.GET.get('start_date')
end = request.GET.get('end_date')
test_var = 'Hello'
return render(request, 'schedule/test.html', locals())
测试.html
{% extends "base.html" %}
{% block content %}
<form method="get">
<table>
{{ form.as_table }}
<tr><td><input type="submit"></td><td></td></tr>
</table>
</form>
<br/>
<b>Start date</b>: {{ start }}<br />
<b>End date</b>: {{ end }}<br />
<b>Test var:</b> {{ test_var }}
{% endblock %}
看起来 SelectDateWidget 没有正确设置 {{ start }} 和 {{ end }} 变量:
我究竟做错了什么?