Django使用本地css js檔案

2022-07-05 07:30:09 字數 861 閱讀 8989

在網上看了很多說django如何使用本地css/js的文章, 但都不能用

今天終於找到乙個可以用的, 記錄下

在manager.py同層級下建立static資料夾, 裡面放上css , js, image等檔案或者資料夾

我的資料夾層級

然後很簡單,只需在settings.py中進行設定就行, 在末尾新增以下**

static_url = '

/static/

'here =os.path.dirname(os.path.abspath(__file__))

here = os.path.join(here, '

../'

)staticfiles_dirs =(

# put strings here, like

"/home/html/static

" or "

c:/www/django/static".

# always use forward slashes, even on windows.

# don

't forget to use absolute paths, not relative paths.

os.path.join(here, '

static/'),

)

在需要使用的html檔案中通過以下方式匯入

"

stylesheet

" href="

../static/style/medicine.css

" />

django 模板使用css js

開啟 settings.py 中的 debug true 同時我們還會做如下操作 1.設定 static root os.path.join os.path.dirname file static 2.設定 static url static 以上兩步我想一般都會提到,但即使你做了這樣的配置,當你在...

django專案使用css js等靜態檔案

要在 django的模板 中引用css js image 等靜態檔案,首先將 settings.py 中debug 設為true。1.在project 目錄下建立乙個存放靜態檔案的目錄,如 static 2 在urls.py的patterns 中增加一行 r static p.django.view...

django載入css js等內容

官方文件 1.新建乙個目錄static,這個目錄與templates和manage.py都在同乙個目錄下 2.將css js等目錄都拷到static目錄下 3.再在setting.py中新增如下內容 static url static project path os.path.abspath os....