Reference the context variable name using double curly braces:
{{ test }}
See the docs for a longer description.
Вопрос
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 }}