【发布时间】:2019-12-11 11:42:00
【问题描述】:
url查询字符串拼写错误如何抛出异常?
解释:
这是获取特定用户的网址:
http://127.0.0.1:5000/v1/t/user/?user_id=1。
如果忍者将点击http://127.0.0.1:5000/v1/t/user/,它将给出用户列表。
问题:
如果查询字符串中的user_id 拼写错误,比如错误use_id=1,或者不是传递整数值,而是传递字符串值到user_id,我希望在这种情况下我应该返回404 页。我不认为内部request.args.get() 会抛出?如果我必须处理这种情况怎么办?
我的部分代码:
page_index = request.args.get('index', 1, type=int)
max_item = request.args.get('max', 1, type=int)
userID = request.args.get('user_id', type=int)
【问题讨论】:
标签: python python-3.x flask