How to pass date with SelectDateWidget?

I'm trying to make this simple code to work:

class TestForm(forms.Form):
    start_date = forms.DateField(widget=SelectDateWidget())
    end_date = forms.DateField(widget=SelectDateWidget())

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())


{% extends "base.html" %}

{% block content %}
    <form method="get">
        {{ form.as_table }}
        <tr><td><input type="submit"></td><td></td></tr>
    <b>Start date</b>: {{ start }}<br />
    <b>End date</b>: {{ end }}<br />
    <b>Test var:</b> {{ test_var }}

{% endblock %}

It looks that SelectDateWidget does not set {{ start }} and {{ end }} variables correctly:

What am I doing wrong?


form values are accessed via cleaned data, try:

start = form.cleaned_data.get('start_date')
end = form.cleaned_data.get('end_date')

if you want the get parameters they are passed by day, month and year:

print: request.GET will give you:

<QueryDict: {u'end_date_day': [u'4'], u'start_date_day': [u'1'], u'end_date_year': [u'2012'], u'end_date_month': [u'3'], u'start_date_month': [u'2'], u'start_date_year': [u'2012']}>

Need Your Help

Drupal comments per fields

drupal cck

I have been looking all over for this, but so far without any luck. Is there a way to have comments per field instead of per node in drupal? If there are no modules available for this, do you think...

Python: How to determine the specific Linux distribution being used?

python linux

I would like to know how to determine the precise Linux distribution I am on (excluding version numbers), from within a Python script and define a variable as equal to it. Now, I should clarify and...