本文共 617 字,大约阅读时间需要 2 分钟。
code.py
import web# render = web.template.render('E:\\py_demo\\py_demo\\templates')root = os.path.dirname(__file__)templatesPath=root+'\\templates\\'render = web.template.render(templatesPath)urls = ( '/(.*)', 'index')class index: def GET(self,name): i = web.input(name=None) return render.index(i.name)if __name__ == "__main__": app = web.application(urls, globals()) app.run()
tmplates/index.html
$def with (name)$if name: I just wanted to say hello to $name.$else: Hello, world!
运行code.py
python code.py 127.0.0.1:8080 打开浏览器输入http://127.0.0.1:8080/?name=lin 得到I just wanted to say hello to lin.转载地址:http://eukvf.baihongyu.com/