建立好的目錄結構以下:javascript
能夠看到在settings裏django自動加了路徑,不須要咱們手動再去加模板路徑。php
靜態文件,不會有變化的文件,好比樣式css文件,js文件,jquery文件,這些不變的文件須要放一個目錄下,瀏覽器在請求的時候請求到指定的目錄就行。css
建立靜態文件目錄,將靜態文件都放進去:html
03 django路由層\django_urls\staticsjava
settings配置靜態文件目錄:STATICFILES_DIRS = [os.path.join(BASE_DIR,'statics'),] # 指定靜態文件地址,全部的靜態文件都放這個目錄jquery
實現h3標籤的點擊事件,原本是紅色,點擊變綠色。django
03 django路由層\django_urls\django_urls\urls.py瀏覽器
from django.contrib import admin from django.urls import path from app01 import views urlpatterns = [ path('admin/', admin.site.urls), path('index/', views.index), ]
03 django路由層\django_urls\app01\views.pyapp
from django.shortcuts import render # Create your views here. def index(request): return render(request,'index.html')
03 django路由層\django_urls\templates\index.html字體
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>首頁</title> <link rel="stylesheet" href="/static/app01/my.css"> </head> <body> <h3>Hello World!</h3> </body> <script type="text/javascript" src="/static/jquery-3.3.1.js"></script> <script type="text/javascript" src="/static/app01/my.js"></script> </html>
03 django路由層\django_urls\statics\jquery-3.3.1.js
jquery下載路徑:https://way2tutorial.com/jquery/jquery_download.php#jquery_download
03 django路由層\django_urls\statics\app01\my.css
h3{
color: red;
}
03 django路由層\django_urls\statics\app01\my.js
$(function () { $('h3').click(function () { this.style.color = "green"; }) });
訪問:http://127.0.0.1:8080/index/
點擊字體後