繁体   English   中英

Django:多种内容类型:text / html出现在html页面上

[英]Django: Multiple Content-Type: text/html appears on html page

我正在研究一个Django项目,该项目可从数据库访问不同的表并将这些信息全部输出到一页上。 我这样做的方式是:

a = get_hostname(request, hostname)
b = get_systeam(request, hostname)
c = get_appteam(request, hostname)

response = HttpResponse()
response.write(a)
response.write(b)
response.write(c)
return HttpResponse(response)

所有调用的函数都通过render_to_response方法返回HTTPresponse对象的地方。 当我使用Javascript查看串联的html时,有多个Content-Type:text / html; charset = utf-8出现在页面上。

<h2>
    <div class ="row">
    <center>
      <div class ="col-md-3 col-md-offset-3">
        <h1>Hostname: xxxxxxx </h1>
      </div>
</h2>
Content-Type: text/html; charset=utf-8



<h3>

    <div class ="row">

      <div class ="col-md-3 col-md-offset-2">
        <h1>System Team: xxxxxx </h1>
      </div>

Content-Type: text/html; charset=utf-8


      <div class = "col-md-3 col-md-offset-2">

        <h1>Application Team: xxxxxxxx </h1>
      </div>


    </div>
</h3>

我感觉没有传递base.html中的meta标签,因此在呈现html块时,它们会自动添加Content-Type行。 任何帮助表示赞赏!

这与meta标签无关。

您应该只创建一个HttpResponse。 您的函数不应使用render_to_response,而应使用render_to_string或直接呈现其内容并返回它们。

此外,函数response中已经有一个HttpResponse,因此您应该只在最后将其返回,而不是将其包装在另一个HttpResponse中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM