03-Flask-url传递参数

config.py

# -*- coding:utf-8 -*-

DEBUG = True

03-url_params.py

# encoding=utf-8

import sys
reload(sys)
sys.setdefaultencoding('utf8')

from flask import Flask
import config
app = Flask(__name__)
app.config.from_object(config)


@app.route('/<id>')
def hello_world(id):
    return '传递的参数是%s'%id


if __name__ == '__main__':
    app.run()

###url传递参数

1.参数的作用:可以在相同的url,但是指定不同的参数,来加载不同的数据

2.在flask中使用参数

  

@app.route('/<id>')
def hello_world(id):
    return '传递的参数是%s'%id

参数需要在两个尖括号中
视图函数需要放和url中的参数同名的参数
  
原文地址:https://www.cnblogs.com/wgDream/p/7399508.html