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 8194299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:46:32+00:00 2026-06-07T04:46:32+00:00

I’m trying to program a calendar app using Django and I can’t seem to

  • 0

I’m trying to program a calendar app using Django and I can’t seem to get it to show the days of the month. For monthly views in views.py I have:

from datetime import date, datetime, timedelta
import calendar

@login_required
def month(request, year, month, change=None):
    """Listing of days in `month`."""
    year, month = int(year), int(month)

    # apply next / previous change
    if change in ("next", "prev"):
        now, mdelta = date(year, month, 15), timedelta(days=31)
        if change == "next":   mod = mdelta
        elif change == "prev": mod = -mdelta

        year, month = (now+mod).timetuple()[:2]

    # init variables
    cal = calendar.Calendar()
    month_days = cal.itermonthdays(year, month)
    nyear, nmonth, nday = time.localtime()[:3]
    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:
        entries = current = False   # are there entries for this day; current day?
        if day:
            entries = Entry.objects.filter(date__year=year, date__month=month, date__day=day)
            if day == nday and year == nyear and month == nmonth:
                current = True

        lst[week].append((day, entries, current))
        if len(lst[week]) == 7:
            lst.append([])
            week += 1

    return render_to_response("cal/month.html", dict(year=year, month=month, user=request.user, month_days=lst, mname=mnames[month-1]))

For the yearly template, I have:

{% extends "cal/base.html" %}

{% block content %}
<a href="{% url cal.views.main year|add:'-3' %}">&lt;&lt; Prev</a>
<a href="{% url cal.views.main year|add:'3' %}">Next &gt;&gt;</a>

    {% for year, months in years %}
        <div class="clear"></div>
        <h4>{{ year }}</h4>
        {% for month in months %}
            <div class=
            {% if month.current %}"current"{% endif %}
            {% if not month.current %}"month"{% endif %} >
                {% if month.entry %}<b>{% endif %}
                <a href="{% url cal.views.month year month.n %}">{{ month.name }}</a>
                {% if month.entry %}</b>{% endif %}
            </div>

            {% if month.n == 6 %}<br />{% endif %}
        {% endfor %}
    {% endfor %}
{% endblock %}

That displays the months in a year. But when I click on the month, it doesn’t display the days.

For the monthly template, I have:

{% extends "cal/base.html" %}

{% block content %}
<a href= "{% url cal.views.month year month "prev" %}">&lt;&lt; Prev</a>
<a href= "{% url cal.views.month year month "next" %}">Next &gt;&gt;</a>

<h4>{{ mname }} {{ year }}</h4>

<div class="month">
    <table>

    <tr>
        <td class="empty">Mon</td>
        <td class="empty">Tue</td>
        <td class="empty">Wed</td>
        <td class="empty">Thu</td>
        <td class="empty">Fri</td>
        <td class="empty">Sat</td>
        <td class="empty">Sun</td>
    </tr>

    {% for week in month_days %}
        <tr>
        {% for day, entries, current in week %}

            <!-- TD style: empty | day | current; onClick handler and highlight  -->
            <td class= {% if day == 0 %}"empty"{% endif %}
            {% if day != 0 and not current %}"day"{% endif %}
            {% if day != 0 and current %}"current"{% endif %}
            {% if day != 0 %}
                onClick="parent.location='{% url cal.views.day year month day %}'"
                onMouseOver="this.bgColor='#eeeeee';"
                onMouseOut="this.bgColor='white';"
            {% endif %} >

            <!-- Day number and entry snippets -->
            {% if day != 0 %}
                {{ day }}
                {% for entry in entries %}
                    <br />
                    <b>{{ entry.creator }}</b>: {{ entry.short|safe }}
                {% endfor %}
            {% endif %}
            </td>
        {% endfor %}
        </tr>
    {% endfor %}
    </table>

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

I don’t think it’s a problem with the way I’ve constructed my monthly view. Rather, I think it’s a problem with the way I’ve linked my yearly template to my monthly template. I’m new to Django and programming in general, so if anyone can point me in the right direction, I’d greatly appreciate it.

Edit:

Here is my urlconf in app/urls.py:

from django.conf.urls import patterns, include, url
from cal.views import main
from cal.views import month
from cal.views import day

urlpatterns = patterns('',
    (r'^(\d+)/$', main),
    (r'', main),
    (r'^month/(\d+)/(\d+)/(prev|next)/$', month),
    (r'^month/(\d+)/(\d+)/$', month),
    (r'^month$', month),
    (r'^day/(\d+)/(\d+)/(\d+)/$', day),
)

Main handles the template for the yearly view.

  • 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-06-07T04:46:33+00:00Added an answer on June 7, 2026 at 4:46 am

    So I’m guessing that main is the view that produces the year/month list. The trouble is that the second regex for that matches everything, because you don’t anchor it. You need this:

    (r'^$', main),
    

    so that it only matches the string where there is nothing between the start and the end – ie the empty string.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

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.