From 5c4686c371ce8552aa503ff46c3916671031b0e1 Mon Sep 17 00:00:00 2001 From: "M.R. Sopacua" <144725145+msopacua@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:41:59 +0100 Subject: [PATCH] fix(3276): Use get_template() The `get_template()` call correctly fetches the template via the engine, but to get the same template type as the one used in the other branch, we need to access its template attribute, where the original template is stored. The engine template wrap the base template to allow direct rendering by TemplateResponse, however this conflicts with the "template via static files" approach taken by Strawberry. Since I'm unfamiliar with the reasoning for this approach, we'll leave it in tact. --- strawberry/django/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/strawberry/django/views.py b/strawberry/django/views.py index 5a09e4b71d..93ac6401ee 100644 --- a/strawberry/django/views.py +++ b/strawberry/django/views.py @@ -17,7 +17,7 @@ from django.http.response import HttpResponse from django.template import RequestContext, Template from django.template.exceptions import TemplateDoesNotExist -from django.template.loader import render_to_string +from django.template.loader import get_template from django.template.response import TemplateResponse from django.utils.decorators import classonlymethod, method_decorator from django.views.decorators.csrf import csrf_exempt @@ -215,7 +215,7 @@ def dispatch( def render_graphql_ide(self, request: HttpRequest) -> HttpResponse: try: - template = Template(render_to_string("graphql/graphiql.html")) + template = get_template("graphql/graphiql.html").template except TemplateDoesNotExist: template = Template(self.graphql_ide_html) @@ -274,7 +274,7 @@ async def dispatch( # pyright: ignore async def render_graphql_ide(self, request: HttpRequest) -> HttpResponse: try: - template = Template(render_to_string("graphql/graphiql.html")) + template = get_template("graphql/graphiql.html").template except TemplateDoesNotExist: template = Template(self.graphql_ide_html)