作者fealing (fealing)
看板Python
標題[問題] 新手請問關於css,js,圖片靜態文件
時間Wed Aug 31 15:40:24 2016
大家好
剛學習django不久,現在遇到了一個問題
以下是app的配置圖
- mysite
-static (css,image,js都放在這裡)
-templates (hello_wprld.html)
-trips
#setting.py#
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
('css','\mysite\static\css'),
('font','\mysite\static\font'),
('js','\mysite\static\js'),
('sass','\mysite\static\sass'),
('image','\mysite\static\image'),
執行
http://127.0.0.1:8000/hello_world.html
css,js,圖片都沒有載入,只有我html裡寫的table Q__Q
如果直接連過去看,有些js或css的程式碼可以顯示出來
ex:
http://127.0.0.1:8000/static/js/init.js
下面截取圖片code,請大家幫我看看
<img src="{% static '/static/image/1.jpg' %}" alt="My image"/>
不好意思問題很雜很亂,實在是沒有頭續,還請大家幫忙
非常感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.227.157.49
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1472629230.A.7F5.html
→ uranusjr: 不要用反斜線, 請一律用 / (內容我沒看) 08/31 16:54
不好意思,不小心打錯了,我是用 / 已修改 多謝提醒
※ 編輯: fealing (125.227.157.49), 08/31/2016 17:07:58
推 gn00672312: template有加 {% load staticfiles %} 嗎 08/31 17:27
→ fealing: 有的,現在我換成超簡單的css可是還是load不進去QQ 08/31 18:00
→ TCUMI: 應該是 {% static 'image/1.jpg' %} 這個樣子吧 08/31 18:14
→ gn00672312: 樓上說的沒錯 看起來path多一個static, 你可以用bro 08/31 18:52
→ gn00672312: wser 的開發人員工具檢查django幫你轉換的路徑對不 08/31 18:52
→ gn00672312: 對 08/31 18:52