-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
29 lines (23 loc) · 876 Bytes
/
example.py
File metadata and controls
29 lines (23 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from application import Application, Response
import os
# Ensure the templates directory exists
if not os.path.exists('templates'):
os.makedirs('templates')
app = Application()
@app.route('/')
def home(request):
skills = {"python": "98%"}
return Response(app.render_template('home.html', skills))
@app.route('/api/data', methods=['GET', 'POST'])
def api_data(request):
if request.method == 'GET':
return Response.json({'message': 'This is GET data', 'query_params': request.query_params})
elif request.method == 'POST':
json_data = request.get_json()
return Response.json({'message': 'This is POST data', 'received_data': json_data})
@app.route('/hello')
def hello(request):
name = request.query_params.get('name', ['World'])[0]
return Response.html(f'<h1>Hello, {name}!</h1>')
if __name__ == '__main__':
app.run()