Template Being Rendered As Text #297
-
|
I'm using this code: When I request the page it just displays the generated html as text: I'm having a hard time figuring out why it's just displaying as text instead of html, using send_file with precompiled html works fine |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I apologize for this. Reviewing the docs I do see how this can be difficult to figure out. The default content type that Microdot uses in responses is You have two options. Either you explicitly give a content type: return Template("admin/admin.html").render(psks=psks), {"Content-Type": "text/html"}or else you configure HTML as a default content type at the top of the file: from microdot import Response
Response.default_content_type = "text/html"Documentation link: https://microdot.readthedocs.io/en/latest/intro.html#changing-the-default-response-content-type. I need to see how to make this more visible! |
Beta Was this translation helpful? Give feedback.
I apologize for this. Reviewing the docs I do see how this can be difficult to figure out.
The default content type that Microdot uses in responses is
text/plain. This is used for any responses that do not included an explicit content type. Thesend_filefunction uses the file extension to define the content type, so those work automatically, but for templates the file extension isn't reliable (some people use.tplfor example) so it isn't used.You have two options. Either you explicitly give a content type:
or else you configure HTML as a default content type at the top of the file: