Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6176785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:09:45+00:00 2026-05-24T00:09:45+00:00

I am trying to build a calendar view using django and trying to avoid

  • 0

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,

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

and in my view, i did the following

<div class="calendar_panel_bottom_noborder">
    <span class="month">Juny 2011</span>
    <span class="day_name">S</span>
    <span class="day_name">M</span>
    <span class="day_name">T</span>
    <span class="day_name">W</span>
    <span class="day_name">T</span>
    <span class="day_name">F</span>
    <span class="day_name">S</span>
    {% for week in month_days %}

        {% for day in week %}
            <span class="date">{{ day }}</span>
        {% endfor %}

    {% endfor %}
    <div class="clear"></div>


</div>

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?

UPDATE

It seems like the problem is coming from itermonthdays. I tried to do the following

>>> month_days = cal.itermonthdays(2011, 12)
>>> 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

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:09:46+00:00Added an answer on May 24, 2026 at 12:09 am

    You need to include

    cal.setfirstweekday(6)
    

    before

    monthdays = ...
    

    According to python documentation, …

    By default, these calendars have Monday as the first day of the week,
    and Sunday as the last (the European convention).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a calendar that looks like Android internal Calendar. The thing
I'm trying to build a quick overview that shows the upcoming calendar week. I
I am trying to build an application that shows a Calendar with events that
I'm trying to build a selectable calendar that show's me some kind of availability.
Im trying to build call to action button on my site using jQuery. I
I'm trying to build a Dynamics CRM 4 query so that I can get
I'm trying to read a calendar feed from http://meetup.com/ , but it seems that
I am trying build a DataTable one row at a time using the following
I'm trying build a conditions array to be using in a prepared statement: Cars.find(:all,
Im trying to build a little site using XML instead of a database. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.