[英]django calling a python script shows the html code instead of a webpage
我的django應用程式呼叫python指令碼(query.cgi)。 但是當我運行它時,網站將顯示該腳本的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")
該網頁顯示:
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>
謝謝你的幫助!!
return HttpResponse(output, content_type="text/plain")
它返回轉義HTML的原因是因為您擁有content_type='text/plain'
,這表明您只是在發送純文本。
嘗試將其更改為'text/html'
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.