pass context data with templateview in django
# views.py
from django.views.generic import TemplateView
class MyTemplateView(TemplateView):
template_name = 'my_template.html'
def get_context_data(self, kwargs):
context = super().get_context_data(kwargs)
context['my_variable'] = 'Hello, World!'
return context
<!-- my_template.html -->
<!DOCTYPE html>
<html>
<head>
<title>My Template</title>
</head>
<body>
<h1>{{ my_variable }}</h1>
</body>
</html>