2017-08-07 26 views
0

我正在Web瀏覽器中運行python cgi腳本。所有的工作都很好,但只要代碼執行完畢,所有的css樣式就會消失(html表單仍然顯示並且工作正常)。我怎樣才能解決這個問題?這裏是我的代碼:使用Python CGI的CSS樣式表

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <link rel="stylesheet" href="/css/style.css" type="text/css" charset="utf-8"> 
    <title>Python Index Match</title> 
</head> 

<body> 
    <form action="/cgi-bin/form.py"> 
     <tag>Welcome!</tag> 
     <p class="text">Please browse for your company file: <input type="file" name="file1" value="Browse"> </p> 
     <span class="btn"></span> 
     <p class="text">Please browse for your price export file: <input type="file" name="file2" value="Browse"> </p> 
     <span class="btn"></span> 
     <p class="text">What company is this file for?  <select name="dropdown"> </p> 
     <option></option> 
     <option value="...">...</option> 
     <option value="...">...</option> 
     </select> 
     What would you like to name your new file? (With extension) <input type="text" name="result"><br> 
     <br> 
     <input type="submit"> 
    </form> 
</body> 

</html> 

這裏是之前和之後的圖像: Before code runs After code finishes running

回答

0

你的CGI腳本應該發出一個HTTP代碼「重定向」到你要顯示的頁面。

# Do not "print(...)" above this 
location = "http://where/you/want/to/browse" # URL may be relative 
# The first two "print(...)" 
print("Content-Type: text/html") 
print("Location: {}".format(location)) 
print() # Empty line (important) 
print("<html><body>Redirecting, please wait.</body></html>") 
+0

這是我有: 打印( 「內容類型:text/html的;字符集= UTF-8 \ r」) 打印( '\ r') – em0em7

+0

重要的是'打印( 「位置...」),該行應該告訴瀏覽器在給定的URL上加載頁面。 – glenfant

+0

然後使用Firefox或Chrome開發工具檢查服務器和瀏覽器之間的真實對話框(標題,內容)並查看出了什麼問題。 – glenfant