Reputation: 103
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
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