flask简

flask采用jinja2作为模板语言,其强大程度高于django所带模板引擎。

from flask import Flask,render_template,request,url_for

app = Flask(__name__,static_folder='static',)        #实例化一个Flask对象,可设置其静态文件位置,模板路径等等参数,静态文件路径默认是static,模板路径默认是temlates


@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route("/login")
def login():
    return render_template("login.html")
@app.route("/index/<int:username>")
def index(username):
    return "%s"%(username)

with app.test_request_context():
    print(url_for("index",username=123))               #url_for构造路径,格式:url_for(函数名,函数参数)----->/index/123

if __name__ == '__main__':                             #在此脚本下运行app
    app.run(debug=True)

猜你喜欢

转载自www.cnblogs.com/gaoyukun/p/9345509.html