简体   繁体   English

django调用python脚本会显示html代码而不是网页

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

my django app calls a python script(query.cgi). 我的django应用程式呼叫python指令码(query.cgi)。 but when I run it, the website shows the html printout from that script instead of showing the output as a webpage. 但是当我运行它时,网站将显示该脚本的html打印输出,而不是将输出显示为网页。

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. 它返回转义HTML的原因是因为您拥有content_type='text/plain' ,这表明您只是在发送纯文本。

Try changing it to 'text/html' . 尝试将其更改为'text/html'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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