简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM