forked from yoki123/rpi-car
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (31 loc) · 828 Bytes
/
app.py
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
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*
from flask import Flask, render_template, request, abort
from car import Car
from config import WEB_PORT
app = Flask(__name__)
car = Car()
handle_map = {
'forward': car.forward,
'left': car.left,
'right': car.right,
'pause': car.stop,
'backward': car.backward,
}
@app.route('/', methods=['GET'])
def main_page():
return render_template("index.html")
@app.route('/handle', methods=['GET'])
def handle():
try:
# 获取GET参数
operation = request.args.get('type', '')
except ValueError:
abort(404) # 返回 404
else:
if operation in handle_map.iterkeys():
handle_map[operation]()
else:
abort(404)
return 'ok'
if __name__ == '__main__':
app.run(host="0.0.0.0", port=WEB_PORT, debug=False)