-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbackend.py
More file actions
27 lines (22 loc) · 824 Bytes
/
backend.py
File metadata and controls
27 lines (22 loc) · 824 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
from flask import request
import dataiku
from flask import session
app.secret_key = "something-from-os.urandom(24)"
app.session_cookie_name = "my-flask-session"
@app.before_request
def session_management():
session.permanent = True
# set a value in the model
@app.route('/set', methods=['POST'])
def set():
for k in ['X', 'Y']:
if k in request.form:
session[k] = request.form[k]
return json.dumps({'X':session.get("X", None), 'Y':session.get("Y", None)})
# compute something based on the state of the model
@app.route('/get-plot', methods=['GET'])
def refresh_plot():
x = session.get("X", 0)
y = session.get("Y", 0)
html = '<div style="background: blue; opacity: 0.5; position: absolute; left: %s%%; top: %s%%; width: 10px; height: 10px"></div>' % (x, y)
return html