靜態檔案配置

2022-09-07 03:06:12 字數 1200 閱讀 4697

static_url靜態檔案urlstatic_root 靜態檔案根路徑,開發環境才用,收集所有靜態檔案,不能和staticfiles_dirs  重合

django的settings中包含三個static相關設定項:

static_root

static_url

staticfiles_dirs

static_url 好理解,就是對映到靜態檔案的url,一般為/static/

static_root 是總的static目錄,可以使用命令自動收集static檔案

比如djangodemo/djangodemo/static 放置公共靜態檔案

可以這麼設定:?1

2345

6789

static_root='/www/djangodemo/djangodemo/static '

static_url='/static/'

staticfiles_dirs=(

'djangodemo/static',

'demo1/static/',

'demo2/static/',

)

使用命令?1

manage.py collectstatic

就會自動把所有靜態檔案全部複製到static_root中

如果開啟了admin,這一步是很必要的,不然部署到生產環境的時候會找不到樣式檔案

來自為知筆記(wiz)

mysql 靜態檔案配置檔案 靜態檔案

靜態檔案 預設情況下所有的 html 檔案都是放在 templates 資料夾內的。什麼是靜態檔案 預設情況下 所用到的靜態檔案資源全部都會放到static資料夾下,django中需要手動建立這個資料夾,static 資料夾下面還可以建立其他的資料夾,將css js檔案區分開來,為了更加方便的管理檔...

Django靜態檔案配置

最近用django開發專案,發現django的靜態檔案 js,css和img等 配置比較麻煩,開發環境和生產環境的配置還不一樣,這裡記錄一下,作為備忘。我當前使用的版本是django v1.4.3。吐槽 django的版本不相容是個大問題,網上搜尋相關問題時,解決方案到是一大推,但是均沒有標註版本,...

Django 靜態檔案配置

django 在自身的開發伺服器上有著自身的淺藍色排版。部署到apache伺服器上會呈現一種無排版狀態。原因是 static 靜態檔案沒有配置。1.在設定檔案 settings.py 裡,新增 static url static static root os.path.join base dir,s...