自己參照網上教程寫的一個wsgi服務器,但是發現加載主頁的時候,圖片加載不出來,還有woff和ttf樣式也加載不出來。
看了程式的運行結果發現不管怎么改,圖片還是出不來。。。
```
#圖片樣式
if path.startswith("/static/images"):
#要訪問靜態檔案
file_name = path[14:]
#打開檔案,讀取內容
try:
file = open(IMAGE_ROOT_DIR + file_name, "rb")
except IOError:
# 代表未找到路由資訊,404錯誤
status = "404 Not Found"
headers = []
start_response(status, headers)
return "not Found"+file_name
else:
file_data = file.read()
file.close()
status = "200 OK"
headers = []
start_response(status, headers)
return file_data
```
然后我自己寫了個測驗程式,發現我這樣寫可以讀出來,但是到服務器打開主頁那邊就出不來不知道為什么。
```
f = open("../html/fonts/glyphicons-halflings-regular.ttf", "rb")
data = f.read()
print(type(data))
print(data)
f.close()
```
圖片那邊全部被掛起了。。。

這是程式列印的錯誤:

我知道各位肯定想說要decode。。。但是decode還是沒用。。。

圖片還是沒出來

有沒有大佬給萌新講解下怎么解決。。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/115659.html
標籤:應用服務器
上一篇:畢業設計做前端+資料庫的管理系統
下一篇:大神求救!!!!
