pywebio

from pywebio.platform.flask import webio_view, FlaskHttpContext

from flask import Flask, request ,send_from_directory, current_app, url_for

from pywebio.input import *

from pywebio.output import *

from pywebio.session import *

app = Flask(__name__)

def bmi():

 current_url = eval_js("window.location.href")

 from urllib.parse import urlsplit, parse_qs

 query = urlsplit(current_url).query

 params = parse_qs(query)

 # Convert the dictionary values from lists to single values

 flat_params = {k: v[0] for k, v in params.items()}

 put_text(flat_params)

 #put_text(current_url)

 height = input("Input your height(cm)：", type=FLOAT)

 weight = input("Input your weight(kg)：", type=FLOAT)

 BMI = weight / (height / 100) ** 2

 top_status = [(16, 'Severely underweight'), (18.5, 'Underweight'),

 (25, 'Normal'), (30, 'Overweight'),

 (35, 'Moderately obese'), (float('inf'), 'Severely obese')]

 for top, status in top_status:

 if BMI <= top:

 put_text('Your BMI: %.1f. Category: %s' % (BMI, status))

 break

app.add_url_rule('/tool', 'test', webio_view(bmi), methods=['GET', 'POST', 'OPTIONS'])

#, provide_automatic_options= True)

app.run(host='0.0.0.0', port=8888)

‎