您的位置:首页 > 其它

flask-restful中url_for的使用

2015-06-23 16:03 267 查看
资源路径定义如下:

api.add_resource(UserResource,'/users/<int:id>', endpoint='get_user', methods=['GET'])


使用flask中的url_for

print flask.url_for('api.get_user', id = '123')


或者使用flask-restful中包装后的url_for

print api.url_for(UserResource, id = '123')


输出:/api/users/12

参考http://stackoverflow.com/questions/24223628/how-do-i-use-flask-url-for-with-flask-restful
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: