【发布时间】:2015-02-03 21:17:25
【问题描述】:
在不渲染模板的情况下返回 HTML 的最简单方法是什么?
类似:
return HttpResponse('<html><p>Hello!</p></html>')
如果我只是像上面那样做,它会将其呈现为字符串而不是 html。
【问题讨论】:
在不渲染模板的情况下返回 HTML 的最简单方法是什么?
类似:
return HttpResponse('<html><p>Hello!</p></html>')
如果我只是像上面那样做,它会将其呈现为字符串而不是 html。
【问题讨论】:
您需要将内容类型设置为text/html:
return HttpResponse("<html><p>Hello!</p></html>", content_type="text/html")
它应该是default content type,除非您将DEFAULT_CONTENT_TYPE 设置为其他值。
【讨论】: