页面静态化优点: 可以减少数据库的访问, 提高效率
页面静态化四个步骤:
1 获取对应模板文件
template = loader.get_template('对应模板.html')
2 查询所需 对应的数据
就是正常查询数据库,筛选获取需要的数据
context = {
数据1,
数据2 ,
...........
}
3 组合渲染成html字符串------->html_text
html_text = template.render(context)
4 写入指定文件夹
with open(路径, 'w', encodeing = 'utf-8') as f:
f.write(html_text)