flask web(2)jinjia2+render_template

首先环境基本都创建好了,之后的话要做的是包括,连接数据库,运用模板(运行js程序),能在网络上运行。

1.运用模板

from flask import render_template

@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):
    return render_template('hello.html', name=name)

a.Python的render_template()方法能传入模板名和参数,由于name要传入hello.html,所以在视图函数处要定义和初始化变量

b.模板放在templates文件中

c.传入的参数在模板中的使用就需要jinjia2的运用,jinjia2 Python模板语言提供有点像js功能的东西

2.

posted @ 2017-01-14 15:35  lyn流光  阅读(142)  评论(0)    收藏  举报