[英]Flask: 404 The requested URL was not found on the server.
I am trying to run the portion of the code with Curl and Flask.我正在尝试使用 Curl 和 Flask 运行该部分代码。 But I a getting the 404 error.但是我收到了 404 错误。 I am pretty sure I am writing the code right as well.我很确定我也在正确地编写代码。 But it's giving me the error.但它给了我错误。
Code:代码:
@app.route('/todo/api/v1.0/tasks/<int:task_id>', methods=['GET'])
def get_task(task_id):
task = [task for task in tasks if task['id'] == task_id]
if len(task) == 0:
abort(404)
return jsonify({'task': task[0]})
REQEST: curl -i http://localhost:5000/todo/api/v1.0/tasks/2请求:curl -i http://localhost:5000/todo/api/v1.0/tasks/2
Make sure to check where you app.run is.确保检查您的 app.run 在哪里。 It needs to be in the bottom of the file.它需要位于文件的底部。
...
if __name__ = '__main__':
app.run(debug=True)
In Python 3 it's can fix like this for example:在 Python 3 中,它可以像这样修复,例如:
list(filter(lambda t: t['id'] == task_id, tasks))
How to find the length of a "filter" object in python 如何在python中找到“过滤器”对象的长度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.