django calling a python script shows the html code instead of a webpage
<p>my django app calls a python script(query.cgi). but when I run it, the website shows the html printout from that script instead of showing the output as a webpage.</p>

<pre><code>def query(request):
    if request.method == 'GET':
       output = subprocess.check_output(['python', 'query.cgi']).decode('utf-8')
       return HttpResponse(output, content_type="text/plain")
</code></pre>

<p>The webpage shows:</p>

<pre><code>Content-Type: text/html


&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8"&gt;
&lt;link type="text/css" rel="stylesheet" href="css/css_4.css"      media="screen" /&gt;
&lt;title&gt;....&lt;/title&gt;
&lt;/head&gt;&lt;body&gt;.....&lt;/body&gt;&lt;/html&gt;
</code></pre>

<p>Thanks for any help!!</p>

<blockquote>
<pre><code>return HttpResponse(output, content_type="text/plain")
</code></pre>
</blockquote>

<p>The reason it's returning escaped HTML is because you have <code>content_type='text/plain'</code>, which says you are just sending plain text.</p>

<p>Try changing it to <code>'text/html'</code>.</p>

python django