user2607925
user2607925

Reputation: 103

django calling a python script shows the html code instead of a webpage

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.

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

The webpage shows:

Content-Type: text/html


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

Thanks for any help!!

Upvotes: 0

Views: 740

Answers (1)

NS0
NS0

Reputation: 6096

return HttpResponse(output, content_type="text/plain")

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

Try changing it to 'text/html'.

Upvotes: 1

Related Questions