Django中配置css、js

來源:互聯網
上載者:User

要在django的tempalte file中引用css、js、gif等靜態檔案,首先一條setting.py中DEBUG開關開啟。
1、在project目錄下建立一個存放靜態檔案的目錄,如:medias
2、在url.py patterns中增加一行:
   (r'^site_media/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.STATIC_PATH}),
   還要from django.conf import setting
3、在setting.py中加入一行:
   STATIC_PATH='./medias'

如此設定後,就可以在template file 中引用media中存放的靜態檔案了,如:
   <img src='/site_media/django.gif'>

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.