On Wed, Jun 25, 2014 at 7:34 PM, Lee Hinde <leehinde@gmail.com> wrote:
> with view code like so:
>
> import calendar
> months_choices = []
> for i in range(1,13):
> months_choices.append((i, calendar.month_name[i]))
> context['months'] = months_choices
>
>
> and
>
> context['default_month'] = today.month
>
> I have this snippet in a template (my first use of lists like this):
>
> <select name="month">
> {% for month in months %}
> <option {% if default_month == month.0 %} selected {% endif %}
> value="{{ month.0 }}">
> {{ month.1 }}</option>
> {% endfor %}
> </select>
>
>
> The issue is the {% if default_month == month.0 %} always returns false...
> The rest of the select is properly built - I get a number for the value and
> the month name as the label.
>
> Why?
>
Differing types? "1" != 1
Log the repr of both values and see.
Cheers
Tom
PS: Django forms are very good at rendering selects and determining
which one is selected.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1L%2B7USiPBr3LN66AB3ZSFQOc44aqvbu9_6G%3DOwETHEAjw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment