flask简

Posted gaoyukun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)

 

以上是关于flask简的主要内容,如果未能解决你的问题,请参考以下文章