Skip to content

Commit aa2cff7

Browse files
committed
Adding catch all route
1 parent b58b71c commit aa2cff7

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ Host: localhost:5000
7373
}
7474
```
7575

76+
### Not found
77+
78+
#### Request
79+
80+
```
81+
[GET, POST] /not_found HTTP/1.1
82+
Host: localhost:5000
83+
```
84+
85+
#### Error handling
86+
```json
87+
404 NOT FOUND
88+
{
89+
"error": "route not found"
90+
}
91+
```
92+
7693
## VSCode
7794

7895
#### Install extension Python 0.6.0 from Don Jayamanne

python_flask_seed/__main__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
app = Flask('python-flask-seed')
44

55

6-
@app.route('/', methods=['GET'])
7-
def hello():
8-
response = {'message': 'Hello from flask!'}
9-
return make_response(jsonify(response), 200)
10-
11-
126
@app.route('/welcome', methods=['POST'])
137
def welcome():
148
content = request.get_json(silent=True, force=True)
@@ -23,5 +17,17 @@ def welcome():
2317
return make_response(jsonify(response), 400)
2418

2519

20+
@app.route('/', methods=['GET'])
21+
def hello():
22+
response = {'message': 'Hello from flask!'}
23+
return make_response(jsonify(response), 200)
24+
25+
26+
@app.route('/<path:path>', methods=['GET', 'POST'])
27+
def not_found(path):
28+
response = {'error': 'route not found'}
29+
return make_response(jsonify(response), 404)
30+
31+
2632
if __name__ == '__main__':
2733
app.run(host='0.0.0.0', port=5000)

0 commit comments

Comments
 (0)