(一)定義模板
首先在項(xiàng)目里創(chuàng)建templates文件夾,并在?templates文件下創(chuàng)建company文件名字自己取,盡量跟你的app名字保持一致。
在company下創(chuàng)建html文件
(二)修改settings.py文件,設(shè)置TEMPLATES的DIRS值
'DIRS':?[os.path.join(BASE_DIR,?'templates')], ? ? ? templates-----創(chuàng)建的模板名
(三)開(kāi)始對(duì)html文件進(jìn)行編寫(xiě) ? ? ? 其實(shí)整個(gè)html文件是對(duì)界面的一個(gè)渲染
<!DOCTYPE html>
<html>
<head>
????????????<title>首頁(yè)</title>
</head>
<body>
{{departName}}---------------{{}} 固定格式 相當(dāng)于打印 ?我們現(xiàn)在把所有的部門(mén)打印出來(lái)
<ul>--------------------------對(duì)部門(mén)進(jìn)行遍歷
{{%for name in departName}}
? ? <li>{{departName}}</li>
{{%endfor}}
</ul>
</body>
(四)進(jìn)入到views.py文件里 ? ? ? ? ?template_name:html文件所在的路徑。 ?context 里的東西html可以調(diào)用
from django.shortcuts import render
from django.http import HttpResponse
from .models import *
# Create your views here.
#def haha(request):
#? ? ? return HttpResponse('haha...')
def departMoban(request):
? ? ? ? bookinfo_list =depart.objects.all()
? ? ? ? context={ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?---------------------這只是個(gè)字典,目的是為了存儲(chǔ)上面的信息,html文件
? ? ? ? ? ? ? ? 'departName':bookinfo_list, ?-------------------------------------- 里可以調(diào)用。
? ? ? ? ? ? ? ? 'titlt':'這是部門(mén)名'
? ? ? ? }
? ? ? ? return render(request=request,template_name='company/depart_info.html',context=context)
(五)總結(jié)
其實(shí)django ?遵循 vmt框架 ?

(六)代碼測(cè)試