The attached Flask+Brython source code was supposed to print 20 random numbers (between -100 and 100) on the browser screen.
However, it doesn't.
The Brython script is failing to parse JSON data.
How can I fix this?
app.py
from flask import Flask, render_template
from flask import request, redirect
from flask_socketio import SocketIO, emit
async_mode = None
app = Flask(__name__)
socketio_obj = SocketIO(app)
@app.route('/', methods=['GET', 'POST'])
def index():
import random
import json
random_list = []
for i in range(0, 20):
n = random.randint(-100, 100)
random_list.append(n)
json_data = str(json.dumps(random_list))
return render_template('index.html', json_data=json_data)
if __name__ == '__main__':
socketio_obj.run(app, debug=True)
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Brython Test</title>
<script src="../static/brython/Brython-3.11.1/brython.js"></script>
<script src="../static/brython/Brython-3.11.1/brython_stdlib.js"></script>
</head>
<body onload="brython()">
<script type="text/python" src="../static/brython/index.py"></script>
</body>
</html>
index.py
from browser import document, window, console
import os
random_list = "{{json_data}}"
document <= random_list