Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm working on a Django project that accesses different tables from my database and outputting that information all on one page. The way I'm doing that is:

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)

Where all the called functions return HTTPresponse objects through render_to_response methods. When I use Javascript to see the concatenated html, there are multiple Content-Type:text/html; charset=utf-8 that appear on the page.

<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>

I have a feeling the meta tag in what is my base.html isn't being passed so when the html chunks are being rendered they automatically add the Content-Type lines. Any help is appreciated!

share|improve this question
    
What is your desired behavior? –  alecxe Jul 28 at 22:57
    
Trying to access different tables within my database and display the information retrieved in a specific html format (using Bootstrap). However, extra Content-Type lines are being outputted as well. –  user2590486 Jul 28 at 23:07

1 Answer 1

up vote 0 down vote accepted

This has nothing to do with meta tags.

You should only create one HttpResponse. Your functions should not use render_to_response, they should either use render_to_string or just directly render their contents and return them.

Also, in your function response is already an HttpResponse, so you should just return it at the end rather than wrapping it in yet another HttpResponse.

share|improve this answer
    
Thanks!This worked.I originally used get_template and render and I absent-mindedly forgot to delete the HttpResponse. –  user2590486 Jul 28 at 23:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.