From 4e065c8726ed56583ad949b2922553418e749ac8 Mon Sep 17 00:00:00 2001 From: Sergi Pons Freixes Date: Wed, 6 Sep 2023 19:59:11 -0700 Subject: [PATCH] Inherit from HTMLResponse instead of Response on _TemplateResponse (#2272) That way we can get rid of setting the media_type. Also allows using a more specific type (HTMLResponse) on applications/libraries using type annotations. --- starlette/templating.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/starlette/templating.py b/starlette/templating.py index 691cfda93..c2078d22d 100644 --- a/starlette/templating.py +++ b/starlette/templating.py @@ -5,7 +5,7 @@ from starlette.background import BackgroundTask from starlette.datastructures import URL from starlette.requests import Request -from starlette.responses import Response +from starlette.responses import HTMLResponse from starlette.types import Receive, Scope, Send try: @@ -23,9 +23,7 @@ jinja2 = None # type: ignore[assignment] -class _TemplateResponse(Response): - media_type = "text/html" - +class _TemplateResponse(HTMLResponse): def __init__( self, template: typing.Any,