flask框架

#coding=utf-8
from flask import Flask

app = Flask(__name__)

@app.route("/hello/")     url后面加/ ,那么访问地址时不加/也能重定向访问
def hello():
  return "hellow word!"

@app.route("/hello/") 为装饰器,指定跳到下面的视图函数hello,另外一种写法为:

app.add_url_rule("/hello/",view_func=hello)  参考: https://blog.csdn.net/xujin0/article/details/97372499

app.run(debug=True)    参数追加,可开启debug模式(即保存就生效,不需要重启服务,这个网页报错会出详细信息)

路由和视图函数绑定的另外一种写法

def test():

  return 'this is response' 

app.add_url_rule('/test',view_func=test)

原文地址:https://www.cnblogs.com/kaibindirver/p/12252706.html