1. Django Structure
2, the site blog under the creation of Templates folder, specifically for storing template files
3. Create the index.html file under the Templates folder
#index. html
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>First template file</title></Head><Body> <H1>Django Create a third project: Write the first template file</H1></Body></HTML>
4. Modify the views.py file
#Create your views here.#Coding:utf-8 fromDjango.httpImportHttpResponse#Import the templates files required to import the library, note that there is no S fromDjango.templateImportLoader,contextdefIndex (Request):#a second project #return HttpResponse ("Hello,django") #loader, get a templateT=loader.get_template ("index.html") C=Context ({}) #没有写入数据, simply loading the index.html filereturnHttpResponse (T.render (c))
Django Creation Project 3rd: Writing the first template file