自定義模板和靜態文件位置
--1.自定義模板
位置:項目容器內,templates目錄
將settings.py文件的templates的app_dirs由true改為false,阻止按默認方式尋找模板
顯示模板:
from django.shortcuts import render 引入render模塊 return render(request, 'hello.html', context)
在views.py內,引入render模塊,讓render函數代替之前的httpresponse返回,
讓url、views、以及模板相關聯起來
--2.靜態文件
位置:項目容器內,static目錄
settings.py文件設置 STATIC_URL = '/static/' 靜態文件目錄 STATICFILES_DIRS = ( os.path.join(BASE_DIR,'static'), 如何加載靜態文件目錄(本設置是加載根目錄下的靜態文件目錄) )
--3.通用靜態文件和基礎模板
<1.>加載靜態文件目錄
{% load 靜態目錄名稱 %}
<2.>引入靜態文件
{% 靜態文件目錄 ’要引入的靜態文件路徑’ %}
