Reputation: 27816
I have very simple template which I would like to mount via TemplateView
:
urlpatterns = [
...
path('feedback', TemplateView.as_view(template_name='foo/feedback.html',
context=dict(mail=settings.DEFAULT_FROM_EMAIL)),
name='feedback'),
]
But this does not work:
TypeError: TemplateView() received an invalid keyword 'context'.
as_view only accepts arguments that are
already attributes of the class.
How can I add render a template without writing a method?
Upvotes: 1
Views: 1949
Reputation: 27816
You need to use extra_context:
urlpatterns = [
...
path('feedback', TemplateView.as_view(template_name='foo/feedback.html',
extra_context=dict(mail=settings.DEFAULT_FROM_EMAIL)),
name='feedback'),
]
Upvotes: 5