用django寫了一個簡單的web頁面用于資源下載,頁面中的資源是預先放在static中的,在除錯的時候一切正常,但是用Apache部署后,頁面的資源均無法下載,提示找不到檔案或目錄。相關代碼如下:
views.py
def download(request):
aa = request.GET # 資源路徑
bb = request.GET #資源名稱
file = open('static\\files\\' + aa + '\\' + bb, 'rb') #問題出在這一行
response = FileResponse(file)
response = 'application/octet-stream'
# response = 'attachment;filename=\"' + bb + '\"'
response = 'attachment;filename=\"' + escape_uri_path(bb) + '\"'
return response
錯誤提示:No such file or directory: 'static\\files\\xxx1\\xxx2'
訪問時采用
http://127.0.0.1/download/?aa=xxx&bb=xxx2的方式進行。我也試過絕對路徑,根本沒有速度,這個部署中應該怎么操作呢?
uj5u.com熱心網友回復:
自己的貼自己結吧,,,轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/103634.html
