route规则

作者: GHope | 来源:发表于2018-10-10 22:42 被阅读11次

规则

写法:converter:variable_name

converter类型:

string 字符串
int 整形
float 浮点型
path 接收路径,接收的时候是str,/也当做字符串的一个字符
uuid 只接受uuid字符串
any 可以同时指定多种路径,进行限定

例子:

@app.route('/')

@app.route('/get_id/<id>/')

@app.route('/get_float_id/<float:uid>/')

@app.route('/get_path/<path:upath>/')

实现对应的视图函数:

@blue.route('/')
def hello_world():
    return 'Hello Word!'


# 路由匹配规则
# 1、<id>: 默认接收的类型是str
# 2、<string:id>: 指定接收的类型是str(字符串)
# 3、<int:id>: 指定接收的类型是int(整形)
# 4、<float:uid>: 指定接收的类型是float(浮点型)
# 4、<path:upath>: 指定接收的类型是path(URl中的路径)
@blue.route('/get_id/<id>/')
def get_id(id):
    # 匹配str类型的id值
    return 'id: %s' % id


@blue.route('/get_int_id/<int:id>/')
def get_int_id(id):
    # 匹配int类型的id值
    return 'id: %d' % id


@blue.route('/get_float_id/<float:uid>/')
def get_float_id(uid):
    # 匹配float类型的uid值
    return 'id: %.3f' % uid


@blue.route('/get_path/<path:upath>/')
def get_path(upath):
    # 匹配path类型的upath值
    return 'path: %s' % upath

methods请求方法

常用的请求类型有如下几种

GET : 获取
POST : 创建
PUT : 修改(全部属性都修改)
DELETE : 删除
PATCH : 修改(修改部分属性)

定义url的请求类型:

@blue.route('/getrequest/', methods=['GET', 'POST'])

相关文章

  • route规则

    规则 写法:converter:variable_name converter类型: 例子: 实现对应的视图函数:...

  • 路由的概念

    路由文件 位置:application/route.php特性:优先加载Route::get('路由规则',fun...

  • Laravel Route 规则

    请求 URL:http://example.com/role/del 规则1 Route::post('role/...

  • laravel Route&Redirect

    Route Route路由定义 由于route内容相对较多,这里只是做了两条涵盖内容较多的路由规则,只是为了方便记...

  • ARouter

    1.ARouter主要用于不同组件的路由跳转,使用时,目标对象需要使用@Route注解,规则是@Route(pat...

  • 23、TP5的路由参数

    2、修改自定义路由规则文件:/config/route.php: 3、根据URL规则访问:http://tp5.c...

  • VueRouter实现原理

    VueRouter类图 VueRouter类 属性: options:记录构造函数中传入的对象;路由规则route...

  • 基于OC的基础Router实现

    Route 路由实现功能 使用 api导航 服务导航 总结 使用 解析参数 传入参数调用 路由规则 scheme:...

  • SpringCloud系列之网关gateway-4.路由功能详解

    路由三重门 Gateway中可以定义很多个Route,一个Route就是一套包含完整转发规则的路由,主要由三部分组...

  • Flask 快速开始一个hello world

    安装INSTALL 快速开始quickstart app.py 可参考blog 变量规则 可以在route中传递变...

网友评论

    本文标题:route规则

    本文链接:https://www.haomeiwen.com/subject/byajaftx.html