django調用本地jquery檔案

來源:互聯網
上載者:User

標籤:django   調用本地   jquery   

1、設定settings.py

STATIC_URL = ‘/static/‘STATICFILES_DIRS = [    os.path.join(BASE_DIR, ‘static‘),]


2、在項目根目錄下建立static目錄,再建立當前應用程式名稱的目錄,然後建立相關目錄js和css。把相關檔案放入目錄;

# tree static/static/├── css│   └── jquery.datetimepicker.css└── js    └── jquery.js


3、在app的template裡面,建立一個測試頁面abc.html

<!DOCTYPE html><html><head><meta charset="utf-8"> <title>菜鳥教程(runoob.com)</title> <script src="/static/js/jquery.js"></script><script>$(document).ready(function(){  $("button").click(function(){    $("#test").hide();  });});</script></head><body><h2>這是一個標題</h2><p>這是一個段落</p><p id="test" >這是另外一個段落</p><button>點我</button></body></html>



4、設定views

def abc(request):    return render(request,‘abc.html‘)

5、設定urls

urlpatterns = [    url(r‘^admin/‘, include(admin.site.urls)),    url(r‘^abc‘,views.abc,name=‘abc‘),]


6、訪問頁面嘗試jquery是否生效http://192.168.1.232:8000/abc 


本文出自 “鬼迷心竅” 部落格,請務必保留此出處http://dragondragon.blog.51cto.com/6170889/1952390

django調用本地jquery檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.