1、在应用目录下创建一个templates文件夹,而后在文件中创建需要的html文件
2、而后在应用目录的views.py中用render()函数将template加入进来,并且可以传递数据。传入的数据在html中用{{}}数据绑定的形式读取数据。
render()函数:第一个参数为调用它函数的请求,第二个参数为template名称,第三个为传入的数据字典。
from django.shortcuts import render
def template(request):
return render(request, "blog/index.html", {"hello": "hello blog1"})
3、注意:template中html的名字如果相同会起冲突,所以最好在templates文件夹中再创建一个文件夹,而后在里面创建html。