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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:11:57+00:00 2026-05-18T02:11:57+00:00

Hello I’m a Django Beginner. I have a calendar that I want to be

  • 0

Hello I’m a Django Beginner.

I have a calendar that I want to be displayed on every site of my webpage, so I call this {% include "tags/my_calendar.html" %} in my base.html.

As I know so far, I can either display the calendar by creating a custom template tag or by using it in a standard Django view. I tested it with a standard Django view, by calling the calendar function through a urls.py, that works fine.
But I don’t want the calendar being only displayed for a special url.

So can I do this by defining a custom template tag?

I tried this so far:

from django import template
register = template.Library()
@register.inclusion_tag("tags/my_calendar.html")
def calendar():
"""
Show calendar of events for specified month and year
"""
  lToday = datetime.now()
  lYear = lToday.year
  lMonth = lToday.month
  my_workouts = ContestEvent.objects.filter(id__year=lYear, id__month=lMonth)
  lCalendar = WorkoutCalendar(my_workouts).formatmonth(lYear, lMonth)
  return {'calendar':  mark_safe(lCalendar)} 

I override the HTMLCalender class as follows and all this works with Django standard view as mentioned before, but returning a render_to_response:

class WorkoutCalendar(HTMLCalendar):

    def __init__(self, workouts):
        super(WorkoutCalendar, self).__init__()
        # self.workouts = self.group_by_day(workouts)

    def formatday(self, day, weekday):
        if day != 0:
            cssclass = self.cssclasses[weekday]
            if date.today() == date(self.year, self.month, day):
                cssclass += ' today'
            return self.day_cell(cssclass, day)
        return self.day_cell('noday', ' ')

    def formatmonth(self, year, month):
        self.year, self.month = year, month
        return super(WorkoutCalendar, self).formatmonth(year, month)

    def day_cell(self, cssclass, body):
        return '<td class="%s">%s</td>' % (cssclass, body)

My \tags\my_calendar.html looks like this:

{% load calendar_tag %}
<div>
{% calendar %}
</div

What am I doing essentially wrong? I got the following error:

Request Method:     GET
Request URL:    http://127.0.0.1:8000/de/
Exception Type:     TemplateSyntaxError
Exception Value:    

Caught an exception while rendering: maximum recursion depth exceeded  

update1
With the hint of Daniel Roseman to make use of variable syntax {{ calendar }} instead of the tag syntax {% calendar %} I got rid of the recursion error, but my calendar is still not displayed. I make a lot of investigations.

What is wrong here?

update2
after some investigation, I found this helpful short description on how to use custom template tag.
The mistake why the calender didn’t show up, was that I was calling {% include "tags/my_calendar.html" %} in the base.html, instead of calling the function of my tag as {% calendar <parameter> %}. Whereas my tag template was ok, which calls the returned value of the tag function:

{{ calendar }}

  • 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-18T02:11:58+00:00Added an answer on May 18, 2026 at 2:11 am

    Your recursion error is because you are calling the calendar tag inside the template being rendered by that very same tag.

    Your /tags/my_calendar.html file should actually look like this:

    <div>
    {{ calendar }}
    </div>
    

    Note the use of the variable syntax, to show you’re rendering the value passed into the context, rather than the tag syntax. You don’t need to use load, either.

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

Sidebar

Related Questions

Hello I want to get Accurate location so that i have used following link
Hello the problem I'm having is this, I have a landing page (event.php) that
Hello I have a call like this list of digits(436,L). How can I reverse
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
hello all i am working on a project in which i have a webpage
Hello guys i have been using JavaFx scene builder to build a gui that
Hello all and thanks for the attention! I have a problem that must both
Hello everyone I have converted a project in C# to F# that paints the
Hello I have a custom control. This custom control has it's DataContext set to
Hello! I have this trouble: I'm searching reports by date and in html view

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.