【问题标题】:Rendering HTML directly without using a template不使用模板直接渲染 HTML
【发布时间】:2015-02-03 21:17:25
【问题描述】:

在不渲染模板的情况下返回 HTML 的最简单方法是什么?

类似:

return HttpResponse('<html><p>Hello!</p></html>')

如果我只是像上面那样做,它会将其呈现为字符串而不是 html。

【问题讨论】:

    标签: python django


    【解决方案1】:

    您需要将内容类型设置为text/html:

    return HttpResponse("<html><p>Hello!</p></html>", content_type="text/html")
    

    它应该是default content type,除非您将DEFAULT_CONTENT_TYPE 设置为其他值。

    【讨论】:

      猜你喜欢
      • 2014-10-05
      • 1970-01-01
      • 2017-06-04
      • 2019-06-04
      • 1970-01-01
      • 2016-11-13
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多