FLASK
1、确保安装和导入FLASK(pip install Flask)
2、编写最简单的程序 run一下
3、编写含有参数的程序:/../<param> 或者带有多个参数的 /../<param>/<param>
4、编写url动态构建程序:redirect(url_for(’[所要重定向的函数名称],[给目标函数的参数赋值 name = parame]‘)),注意,此时需要再导入两个包,redirect,url_for
程序部分截图如下:
# 导入Flask 包
from flask import Flask, redirect, url_for
# 声明Flask的一个对象
app = Flask(__name__)
# 创建路由1
@app.route('/')
def hello_world():
return "Hello World created by pychrom!"
# 创建路由2
@app.route('/gg/')
def custom():
return str(3 + 2)
# 创建带有字符串变量的路由
@app.route('/hello/<name>/')
def sayHello(name):
return "say hello to %s" % name
# 创建带有int类型的变量flaot、path的同样也可以
@app.route('/number/<int:number>/')
def number(number):
return "number is %d" % number
# URL构建
@ap