문제

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?

도움이 되었습니까?

해결책

Reference the context variable name using double curly braces:

{{ test }}

See the docs for a longer description.

다른 팁

you can add an attrib to it like this :

context_object_name = 'ab_list'

and then in your html :

{{ ab_list }}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top