0

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

1 Answer 1

1
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'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.