IcoVera
IcoVera

Reputation: 13

HTMLCalendar displaying as a String instead of using the HTML properly (Django)

I'm trying to display an HTMLCalendar in my django project but it's only displaying the html code instead of the actual Calendar.

views.py

def CalendarView(request):

    cal = HTMLCalendar().formatmonth(2020, 10, withyear=True).replace('<td ', '<td  width="150" height="150"')

    return render(request, 'calendar.html', {'cal': cal})

calendar.html

{%  extends 'base.html' %}

{% block tilte %} Home {% endblock %}
{% block body %}


  <div id="content-main">
          <ul class="object-tools">
            <li>
                <a href={{ previous_month }}>
                    Previous month
                </a>
            </li>
            <li>
                <a href={{ next_month }}>
                    Next month
                </a>
            </li>
        </ul>

        {{ cal }}

{% endblock %}

This is what gets displayed instead of the actual calendar

Upvotes: 1

Views: 395

Answers (1)

This is what you would want to put instead of just {{ cal }}.

{{ cal|safe }}

Upvotes: 2

Related Questions