Django学习——创建template
1、在应⽤⽬录下创建⼀个templates⽂件夹,⽽后在⽂件中创建需要的html⽂件
2、⽽后在应⽤⽬录的views.py中⽤render()函数将template加⼊进来,并且可以传递数据。传⼊的数据在html中⽤{{}}数据绑定的形式读取数据。
render()函数:第⼀个参数为调⽤它函数的请求,第⼆个参数为template名称,第三个为传⼊的数据字典。
django怎么学
from django.shortcuts import render
def template(request):
return render(request, "blog/index.html", {"hello": "hello blog1"})
3、注意:template中html的名字如果相同会起冲突,所以最好在templates⽂件夹中再创建⼀个⽂件夹,⽽后在⾥⾯创建html。