Reputation:
I have a particular HTML file that I want to show in Django. This file is generated externally and will not use Django template syntax. In fact, it includes some syntax that confuses the Django template generator (like {{ #something }}
) and makes it return an error.
What is the best way to return this particular HTML page in a way that does not trigger the template syntax to be used? I use this now, and it works, but is this the recommended way? Any drawbacks?
def annual_report(request):
from django.http import HttpResponse
html_content = open("templates/reports/annualreport.html")
return HttpResponse(html_content)
Upvotes: 0
Views: 957
Reputation: 4432
It's ok to use HttpResponse
, in fact render
uses HttpResponse
as base class, as well as TemplateResponse
that's based on SimpleTemplateResponse
with parent class HttpResponse
Upvotes: 1