File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed
Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 33app = 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' ])
137def 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+
2632if __name__ == '__main__' :
2733 app .run (host = '0.0.0.0' , port = 5000 )
You can’t perform that action at this time.
0 commit comments