Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding html calendar view using django
    text
    copied!<p>I am trying to build a calendar view using django and trying to avoid writing any html tags inside my view. I found a code that helped me get there, </p> <pre><code>from datetime import date, datetime, timedelta, time import calendar year=2011 month=12 change=None # init variables cal = calendar.Calendar() month_days = cal.itermonthdays(year, month) lst = [[]] week = 0 # make month lists containing list of days for each week # each day tuple will contain list of entries and 'current' indicator for day in month_days: lst[week].append((day)) if len(lst[week]) == 7: lst.append([]) week += 1 </code></pre> <p>and in my view, i did the following</p> <pre><code>&lt;div class="calendar_panel_bottom_noborder"&gt; &lt;span class="month"&gt;Juny 2011&lt;/span&gt; &lt;span class="day_name"&gt;S&lt;/span&gt; &lt;span class="day_name"&gt;M&lt;/span&gt; &lt;span class="day_name"&gt;T&lt;/span&gt; &lt;span class="day_name"&gt;W&lt;/span&gt; &lt;span class="day_name"&gt;T&lt;/span&gt; &lt;span class="day_name"&gt;F&lt;/span&gt; &lt;span class="day_name"&gt;S&lt;/span&gt; {% for week in month_days %} {% for day in week %} &lt;span class="date"&gt;{{ day }}&lt;/span&gt; {% endfor %} {% endfor %} &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>Now, the above code is printing the calendar as per the month and year parameters but they are appearing wrong. When I compare it with the calendar, using december 2011, the first day of the month starts at thursday while in calendar its starting on wednesday. can anyone help point out what I did wrong here?</p> <p><strong>UPDATE</strong></p> <p>It seems like the problem is coming from itermonthdays. I tried to do the following</p> <pre><code>&gt;&gt;&gt; month_days = cal.itermonthdays(2011, 12) &gt;&gt;&gt; for day in month_days: ... print day ... 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 0 </code></pre> <p>I don't know if I should change some sort of a settings or initiate the class differently. But, the output should start with 4 zeros and end with none based on my PC calendar it shows that december 2011 starts on a thursday which is the 5th day of the week therefore there should be 4 zeros before the count starts. hmm any advice on how i can tackle this issue?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload