Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving an html file with django without template rendering?

Tags:

python

django

I have an html file that I generated by creating a visualization using the Bokeh library. I'd like to include it within my django site, however, I get a TemplateSyntaxError when I attempt to add it as a view. It appears that some of the syntax in the page is conflicting with Django's templating system.

How do I go about having Django serve the page without attempting to parse it as a template?

like image 781
orange1 Avatar asked Dec 09 '22 01:12

orange1


1 Answers

Based on the base template docs, you can just return an HttpResponse directly, without using any render functions:

https://docs.djangoproject.com/en/1.8/topics/http/views/

Since the HttpResponse just takes a string for the response content, you could just read the raw file in from wherever it is stored, and return it this way.

When you use render_to_response or render, this just loads the template, parses it, constructs the resulting string, and returns it wrapped in an HttpResponse anyway, so if you don't want to do any rendering, you can skip the template system entirely.

like image 188
zstewart Avatar answered Mar 14 '23 23:03

zstewart