大體的流程:python
參考文檔django
在項目根目錄創建 static 目錄,在 app.conf 中指定 static 目錄是靜態目錄瀏覽器
handlers: - url : /static/(.*) script : /static/$1 - url : /debug/.* script : debug.py - url : /.* script: index.py - expire : .jpg modify 10 years - expire : .swf modify 10 years - expire : .png modify 10 years - expire : .gif modify 10 years - expire : .JPG modify 10 years - expire : .ico modify 10 years
驗證: 在新建的 static 目錄中拷貝一個圖片 1.jpg ,上傳發布代碼後,在瀏覽器中訪問 ***.duapp.com/static/1.jpg 應該可以顯示該圖片。app
設置 STATIC_ROOT 部分,這樣django在收集靜態文件時會把url
SITE_ROOT = os.path.dirname(os.path.abspath(__file__)) SITE_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '../')) STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
python manage.py collectstatic