在函数参数中包含字典的同时将数据发送到python烧瓶中的html仪表板 [英] send data to html dashboard in python flask while having dictionary in a function parameter
问题描述
我想在flask框架中将数据发送到html,我有一个接收字典作为参数的函数,然后在字典上应用了几个函数.在最终结果之后,我想渲染到html页面.我已经从不同的博客尝试了48小时,但没有得到精确的解决方案.
I want to send data to html in flask framework, i have a function which receives dictionary as a parameter, then there are several functions applied on dictionary. after that final result i want to render in to html page. Its been 48 hours i am trying from different blogs but didn't get precise solution.
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)
回溯
推荐答案
Flask可以路由到的方法不要将字典作为输入,并且它们接受的参数必须通过路由中的模式进行匹配.(请参见 https://flask.palletsprojects.com/en/1.1.x/api/#url-route-registrations )
Methods that Flask can route to don't take dictionaries as inputs, and the arguments they do take need to be matches by a pattern in the route. (See https://flask.palletsprojects.com/en/1.1.x/api/#url-route-registrations)
如果您进行更改,将会收到相同的错误
You'd get the same error if you changed
@app.route("/dashboard")
def calculate_full_eva_web(input:dict):
到
@app.route("/dashboard")
def calculate_full_eva_web(input):
您的前进路径取决于发出请求时如何传递数据.您可以通过URL参数传递键/值对,并通过 request.args
对象检索它们.那可能已经足够接近您想要的了.(您需要从 calculate_full_eva_web()
中删除参数声明)
Your path forward depends on how you want to pass data when you make the request. You can pass key/value pairs via URL parameters and retrieve them via the request.args
object. That might be close enough to what you want. (You'll need to remove the argument declaration from calculate_full_eva_web()
)
类似
from flask import request
@app.route('/dashboard')
def calculate_full_eva_web():
input = request.args
...
这篇关于在函数参数中包含字典的同时将数据发送到python烧瓶中的html仪表板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!