-1

I am trying to run the portion of the code with Curl and Flask. But I a getting the 404 error. 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

Andy.W
  • 11
  • 3

2 Answers2

1

Make sure to check where you app.run is. It needs to be in the bottom of the file.

...
if __name__ = '__main__':
    app.run(debug=True)
Andy.W
  • 11
  • 3
0

In Python 3 it's can fix like this for example:

list(filter(lambda t: t['id'] == task_id, tasks))

How to find the length of a "filter" object in python