[Python] Django template is not rendered at all, just the content of the file is shown

Discussão em 'Python' iniciado por Stack, Julho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to add a calendar feature to my Django app. I found this HowTo from Hui Wen which is very nice. But I am stuck as obviously the URL processing changed in the mean-time (the document is from July 2018).

    I changed the elements in urls.py from

    url(r'^index/$', views.index, name='index'),


    to

    path('index/', views.index, name='index'),


    This works, but I do not know how to change this one:

    url(r'^calendar/$', views.CalendarView.as_view(), name='calendar'), # here


    I tried to make an explicit view and render this:

    def calendar(request):
    my_callable_view = CalendarView.as_view() #(request)
    response = my_callable_view(request) # generate proper response
    template = loader.get_template("cal/calendar.html")
    context = {'response':response}
    return HttpResponse(template.render(context, request))


    But this way, the page is just showing

    {'% extends 'cal/base.html' %} {'% block content %} {'{ calendar }} {'% endblock %}


    So I asume, that the template is not rendered at all, this is the content of the file templates/cal/base.html. What would be the correct way to go?

    KR, Christof

    Continue reading...

Compartilhe esta Página