Question

I'm programming my first Django website. I want to pass data from my view to my template.

my view:

from django.views import generic


class AboutView(generic.TemplateView):
    template_name = 'about.html'

    def get_context_data(self, **kwargs):
        ctx = super(AboutView,self).get_context_data(**kwargs)
        ctx['test'] = 'This testtext should be displayed in the Webpage'
        return ctx

my template:

{% extends 'site_base.html' %}
{% block body %}

{% endblock %}

How to display the testtext in the body-block?

Était-ce utile?

La solution

Reference the context variable name using double curly braces:

{{ test }}

See the docs for a longer description.

Autres conseils

you can add an attrib to it like this :

context_object_name = 'ab_list'

and then in your html :

{{ ab_list }}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top