how to send data to html worksheet using flask framework

148 Views Asked by At

I have a function calculate_full_eva_web(input:dict) it receives input dictionary several function applied on this input to create calculations dict, after calculations i want to send this data to html dashboard and after send data to html file i can play there with jinja stuff. i am unable to do so, i tried several ways but flask throws error. and also i don't know much about ajax ,may be ajax will do my work, let me know. that is why i am tagging ajax people on this post. Traceback is also attached..Thank you

In simple words, i want to send data to html in flask ! Please check my code. Let me know if i am doing anything wrong.

imports ...
from other file import other_functions
from other file import other_functions_2
from other file import other_functions_3

app = Flask(__name__, template_folder='templates/')

@app.route("/dashboard")
def calculate_full_eva_web(input:dict):

   calculate_gap = other_functions(input)
   calculate_matrix = other_functions_2(input)
   average = other_functions_3(input)
   data = dict{'calculate_gap':calculate_gap, 'calculate_matrix':calculate_matrix,'average':average}

   return render_template('pages/dashboard.html', data = data) 

if __name__ == "__main__":
    app.run(debug=True)

Traceback

1

There are 1 best solutions below

11
do thuan On

The route receive a dict as input so you must change @app.route("/dashboard") to @app.route("/dashboard/<input>") and pass input to the route in the link of the route.

For example, I have a route as below.

@app.route('/user/<name>') def user(name): return render_template('home.html', name=name) To pass name to the route, I access the link http://localhost:5000/user/myname.