模板中使用python语法:遍历
模板文件中$符号表示是python语法
一、怎么使用模板:
1、在开始(文件头部或者项目入口文件)(templates参数是模板目录):
render = web.template.render('templates');
2、模板文件命名index.html,放到模板目录中;
3、使用render.index(),使用模板文件(方法名与模板文件名要相同)
二、给模板文件传参数
1、render.index(参数名)
2、模板文件顶部增加代码:$def with(参数名)
3、在模板用 $参数名 ,来使用数据
模板文件读取:render.index("参数")
结果数据获取:model.select("sql")
URL跳转:web.seeother("/")
相应处理的方法
响应处理的
pyweb响应处理
模板文件中<!DOCTYPE html>必须删掉
html中使用python语法前要加$
render.hello2(name);
hello2是网页名,name是参数
在hello2中第一行要加 $def with(name)
name为传进的参数,使用时要加美元符 $name
render对象后跟网页名()
模板文件读取 render.index("参数") 结果数据获取 model.select("sql") URL跳转 web.seeother("/")
参数‘temmplats’是存放网页的目录