Skip to content

Commit c098891

Browse files
GettingStarted
0 parents  commit c098891

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

app.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from flask import Flask, request #import main Flask class and request object
2+
3+
app = Flask(__name__) #create the Flask app
4+
5+
@app.route('/query-example')
6+
#def query_example():
7+
# return 'Todo...'
8+
def query_example():
9+
language = request.args.get('language') #if key doesn't exist, returns None
10+
11+
return '''<h1>The language value is: {}</h1>'''.format(language)
12+
13+
@app.route('/form-example')
14+
def form_example():
15+
return 'Todo...'
16+
17+
@app.route('/json-example', methods=['POST']) #GET requests will be blocked
18+
def json_example():
19+
req_data = request.get_json()
20+
print("request_Data",req_data)
21+
language = req_data['language']
22+
framework = req_data['framework']
23+
python_version = req_data['version_info']['python'] #two keys are needed because of the nested object
24+
example = req_data['examples'][0] #an index is needed because of the array
25+
boolean_test = req_data['boolean_test']
26+
27+
return '''
28+
The language value is: {}
29+
The framework value is: {}
30+
The Python version is: {}
31+
The item at index 0 in the example list is: {}
32+
The boolean value is: {}'''.format(language, framework, python_version, example, boolean_test)
33+
34+
35+
if __name__ == '__main__':
36+
app.run(debug=True, port=5000) #run app in debug mode on port 5000

0 commit comments

Comments
 (0)