Django timezones examples - why don't I get any time zones? -


i've made use of example shown in django doco of setting active timezone : https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/#selecting-the-current-time-zone .

the thing template shown there renders nothing in select box . else seems fine .

here's version of it:

    {% load tz %}     {% get_current_timezone time_zone %}     <form action="{% url 'set_timezone' %}" method="post">         {% csrf_token %}         <label for="timezone">time zone:</label>         <select name="timezone">             {% tz in timezones %}             <option value="{{ tz }}"{% if tz == time_zone %} selected="selected"{% endif %}>{{ tz }}</option>                                                                                                    {% endfor %}         </select>         <input type="submit" value="set" />     </form> 

it renders fine select box empty - can explain ?


edits in response comments

my view code looks :

from django.shortcuts import redirect, render

def set_timezone(request):     if request.method == 'post':         request.session['django_timezone'] = request.post['timezone']         return redirect('/')     else:         return render(request, 'template.html', {'timezones': pytz.common_timezones}) 

i can confirm pytz installed. pip freeze includes :

pytz==2015.4 

with respect "where did define timezones ?" that's sort of question. don't understand why code in doco suggests 'timezones' there . wondered if side effect of {% load tz %} otherwise ... yes that's nub of question.


edits in response comments

@anentropic: when i'm missing endfor ... that's not code that's out django doco. maybe it's missing endfor if can't see endfor should be.

for record here's actual template code i'm using (which cut , paste django code)

    <!-- set tz form -->     {% load tz %}     {% get_current_timezone time_zone %}     <form action="{% url 'set_timezone' %}" method="post">         {% csrf_token %}         <label for="timezone">time zone:</label>         <select name="timezone">             {% tz in timezones %}             <option value="{{ tz }}"{% if tz == time_zone %} selected="selected"{% endif %}>{{ tz }}</option>             {% endfor %}         </select>         <input type="submit" value="set" />     </form> 


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -